MySQL Forums
Forum List  »  Newbie

Double Bendback Query
Posted by: Jim R
Date: July 10, 2005 06:42PM

I am trying to determine if such a query can be made (MySQL 4.0.21)

t1 has these colums: id, firstname, lastname
t2 has these columns: id, t1_id, alias_id

If I have a couple of records in t1, which represent aliases for a single individual, like:

230, John D., Smith
545, J. D., Smith

And corresponding records in t2

1, 230, 1
2, 545, 1

The third column indicates that alias_id 1 relates to t1_id's 230 and 545.

Now if I know John D. Smith's record ID of 230, is there a query that will identify the alias_id as 1 and then display all the records in t1 that have an alias_id of 1 in t2?

SELECT alias_id FROM t2 WHERE t1_id = '230'
SELECT firstname, lastname FROM t1 LEFT JOIN t2 ON = t2.t1_id WHERE alias_id = ~result from previous query~

In other words, I would like to take the output of one query and use it as an input to a second query. Preferably without creating temporary tables. Is there a query that does this?

Thanks for your help - Jim

Options: ReplyQuote

Written By
Double Bendback Query
July 10, 2005 06:42PM
July 11, 2005 03:34AM
July 11, 2005 09:20AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.