ttist25
asked on
SQL - Select Description based on ID
Hello,
I have a database with a main table representing people and a bunch of support tables which represent demographic characteristics of those people. The main table has ID#'s for corresponding descriptions in the support tables and I need to figure out how to translate the ID's to Descriptions.
For instance, the main table (tblMain) has a field "Race_ID" which corresponds to the "ID" column in the "Race" support table. (e.g. 1|White, 2|Black, 3|Asian, etc).
I'm trying to figure out how to get the "Race_Description" field from "tblRace" where the "Race_ID" field in "tblMain" matches the "ID" field in "tblRace".
How can I do this?
Thanks!
I have a database with a main table representing people and a bunch of support tables which represent demographic characteristics of those people. The main table has ID#'s for corresponding descriptions in the support tables and I need to figure out how to translate the ID's to Descriptions.
For instance, the main table (tblMain) has a field "Race_ID" which corresponds to the "ID" column in the "Race" support table. (e.g. 1|White, 2|Black, 3|Asian, etc).
I'm trying to figure out how to get the "Race_Description" field from "tblRace" where the "Race_ID" field in "tblMain" matches the "ID" field in "tblRace".
How can I do this?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Select m.*, r.description from tblmain m
Left join tblrace r on m.race_id = r.id
Left join tblrace r on m.race_id = r.id
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a bunch!
ASKER
SELECT Description from tblmain m
LEFT JOIN etc.?