MySQL Forums
Forum List  »  General

Need help with complex SQL query
Posted by: auburnpony
Date: January 21, 2005 05:18PM

I am trying to figure out how to create a single query that, for each record in table1, will retrieve all data for the record in table1 as well as some data from two different records in table2.

Let's say that table1 consists of: table1_id, message, comment, date
and table2 consists of: table2_id, table1_id, message, date

So each record in table2 has an id of one record from table1.

I want a query that will retrieve all data from all records of table1, and for each record from table1, also give me the table2_id of the oldest and newest records from table2.

Can this be done with a couple of JOINs in the query or perhaps a few subqueries? I need to be able to sort the final results so its important for all the data to be retrieved in a single query.

Any help on this matter would be greatly appreciated.

Thanks in advance.

-Auburn

Options: ReplyQuote


Subject
Written By
Posted
Need help with complex SQL query
January 21, 2005 05:18PM


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.