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!

Problems with JOIN

Status
Not open for further replies.

thegman

Programmer
Oct 16, 2001
26
GB
I need to get a list of IDs from a table, and then link those IDs up with a 'pretty' name for the same thing in a different table, rather than use a while loop in perl to get these one at a time, which is very slow, I would like to do a JOIN, but I simply cannot get this to work, I either get all the contents of the table or none at all. What I need to do is something like this.

SELECT A FROM TABLE1 WHERE B = '2';

This would return 5 records, now I need to say:

SELECT PrettyName FROM TABLE2 WHERE A = 'one of those 5 records'.

I have tried a lot of things but cannot seem to get the right results.

TIA

Garry
 
Think this is it :)

-----------------------------
SELECT t1.A, t2.prettyname from TABLE1 t1, TABLE2 t2 WHERE t1.B = '2' and t2.prettyname = t1.A; ***************************************
Party on, dudes!
[cannon]
 
Great, that was exactly what I was after. My mistake was not using the table aliases in the WHERE clause of the statement. Doh!

Thanks a lot.

Garry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top