Hi,
I am working on a plant database and I need some help with a query that i *thought* shouldn't have been too hard =\
I am trying to create a query that will display the names contained in 4 different tables but I am having trouble linking them using the main table containing ids
Here is the structure information for the 4 tables:
Families - family_id int(10)
-
family_name varchar(50)
Genera - genus_id int(10)
-
genus_name varchar(50)
Species - species_id int(10)
-
species_name varchar(50)
Infraspecies - infraspecies_id int(10)
-
infraspecies_name varchar(50)
-
rank varchar(5)
Then the main table:
Plants - plant_id int(10)
-
family_num int(10) families -> family_id
-
genus_num int(10) genera -> genus_id
-
species_num int(10) species -> species_id
-
infraspecies_num int(10) infraspecies -> infraspecies_id
-
syn_genus_num int(10) syn_genera -> syn_genus_id
-
syn_species_num int(10) syn_species -> syn_species_id
-
syn_infraspecies_num int(10) syn_infraspecies -> syn_infraspecies_id
-
scientific_name varchar(100)
-
additional_info text
And I would like the query to print out the family name - genus name - species name - rank - infraspecies name (in that order). How exactly would i go about this, i was trying to do it using joins but that did not work.
Thanks in advance...
4 1942
Welcome to TSDN!
Have you tried a query like the following (not quite correct column names, but the join is what you want) -
SELECT p.plant_id, p.family_num, p.genus_num,p.species_num, p.infraspecies_num, g.genus_name, s.species_name, i.infraspecies_name, f.family_name
-
FROM plants as p,generas g,families as f,species as s,infraspecies as i
-
WHERE p.family_num=f.family_id AND
-
p.genus_num=g.genus_id AND
-
p.species_num=s.species_id AND
-
p.infraspecies_num=i.infraspecies_id;
Ronald
Hey thanks for the tip, i tried the query and it worked but i edited it a bit to show just the fields i wanted. Problem is though that i would like null fields in infraspecies rank and infraspecies name to show up in the results so that i get the full amount of rows from plants table with all relevant information returned. How would i get that done, i'm assuming i would have to use joins somehow but i'm not exactly sure how to go about it.
Thanks
yaaaay, i think i got it lol, here's the query i used: -
SELECT f.family_name, g.genus_name, s.species_name, i.rank, i.infraspecies_name
-
FROM plants AS p
-
LEFT JOIN (
-
genera AS g, families AS f, species AS s
-
) ON ( p.family_num = f.family_id
-
AND p.genus_num = g.genus_id
-
AND p.species_num = s.species_id )
-
LEFT JOIN infraspecies AS i ON p.infraspecies_num = i.infraspecies_id
-
Output seems to be accurate so far plus it returned the correct number of rows from the plants table (2,393)
I was just working on it, but you beat me to it.
Ronald
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Marizel |
last post by:
I'm not sure there's an easy solution to this, but thought I'd ask. I
often find myself with a query which I'd like to reuse, but with a
different datasource. These datasources generally have...
|
by: kiqyou_vf |
last post by:
Sorry, Google wouldn't let me post a reply. Here is the convo thus far:
Jerry Stuckle wrote:
> kiqyou_vf wrote:
>> I'm trying to pull data from 2 different tables and do a loop to
>> retrieve...
|
by: Jimbo |
last post by:
Hello,
I have a user request to build a form in an Access database where the user
can check off specific fields to pull in a query. For example, let's say I
have 10 fields in a table. The user...
|
by: Robert |
last post by:
I am an attorney in a non-profit organization and a self-taught programmer.
I'm trying to create a client db that will allow me to search for potential
conflicts of interest based either on Social...
|
by: PL |
last post by:
Hi,
I have 2 simple tables, 'Accesses' and 'Partners'.
Partners :
- Id, primary numeric key
- Name of the partner
- other informational fields
Accesses :
- Id, primary numeric key
|
by: MVM |
last post by:
Hi,
I am attempting to run a query in MS SQL server between two tables that have
a one to many relationship.
The tables are linked on GID. What I want is one instance of every record
from Table...
|
by: mlcampeau |
last post by:
Hey guys,
I have been mulling over this problem for a few days and have yet to come up with a query that will give me the expected results. I am working on a database that stores employee...
|
by: dreaken667 |
last post by:
I have a MySQL database containing 16 tables of data. Each table has a different number of columns and there are few common field names accross tables. I do have one master table with which I connect...
|
by: zion4ever |
last post by:
Hello good people,
Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |