Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query reference by ID

Status
Not open for further replies.

EricE

IS-IT--Management
Oct 6, 2000
17
US
I always have trouble with this concept when referencing ID's in a database and I was wondering if anybody had any feedback.

If I have the following 2 tables:

table DB_RECORDS has columns ID (int),Name (varchar 25),State_ID (int)

table DB_STATES has columns State_ID (int),State_Name (varchar 30)

When running a query listing out DB_RECORDS is there an efficent way to print out the "State_Name" by referencing the State_ID without running a separate query for each DB_RECORDS result returned? I guess what I am trying to do is reference by ID between 2 tables...

Any insight would be appreciated.

Thanks,

Eric


Eric
 
Code:
SELECT dbr.*, dbs.State_Name FROM DB_RECORDS AS dbr, DB_STATES AS dbs WHERE dbs.State_ID = dbr.State_ID

A LEFT JOIN is another way you can do your query. I'm not sure what database server you use, so I won't get any more specific.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top