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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to combine the following two queies to one

Status
Not open for further replies.

bosky

Programmer
Oct 30, 2003
15
IN
Hi There!


I have 2 queries, each selecting set of records from different tables.

SELECT Distinct(parent_ID) FROM item_audits WHERE created>=date OR edited>=date

SELECT Distinct(parent_ID) FROM item_responses WHERE created>=date

Now i want to combine the above 2 queries to one query.is it possible?

NOTE: all the refered fields are of datetime type

Regards
Bosky

 
I think what you mean is


SELECT DISTINCT Parent_Id FROM (
SELECT parent_ID FROM item_audits WHERE created >= date OR edited >= date
UNION
SELECT parent_ID FROM item_responses WHERE created >= date );



'ope-that-'elps.





G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Thanks for ur reply.

The statement fetches the result i want when i remove the line
"SELECT DISTINCT Parent_Id FROM (" From the above statement.


Thanks a lot.
 
Arrrh.

But if the two separate SELECTS yield the same ParentId then you'll get a duplicate in the result.

You need to add the Distinct to DeDup the combined dynaset.

-or can't they yield matching ParentId values anyway ?





G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
When i use the Distinct Clause it gives me a syntax error, Is there a different way to write the Disticnt clause in MySQL.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top