MYSQL Query help with Union's and Distinct references

I am working on an SQL query that would pull rows from three tables and order them by date. The structure of the tables is:

id - auto incrememnting integer
inquiry - the referenece to the inquiry that this comment relates to
date
comment - text

The problem is, inquiries can have multiple comments and I receive output with duplicating inquiry numbers. I would like a result set with only unique/distinct inquiry numbers, but including the word DISTINCT after each select does not solve this, any ideas?
(SELECT * FROM abc) UNION (SELECT * FROM def) UNION (SELECT * FROM ghi) ORDER BY `date` DESC

Open in new window

Rob--Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
what about this:
select * 
from ( SELECT * FROM abc 
 UNION SELECT * FROM def 
 UNION SELECT * FROM ghi
) 
ORDER BY `date` DESC

Open in new window

0
Rob--Author Commented:
Thanks for the help, after running that query the following error occured:
#1248 - Every derived table must have its own alias
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
sorry for that:
select * 
from ( SELECT * FROM abc 
 UNION SELECT * FROM def 
 UNION SELECT * FROM ghi
)  sq
ORDER BY `date` DESC

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Rob--Author Commented:
This query ran successfully, but it does not produce the same results. The id which is unique is showing up multiple times, which means multiple inquiry numbers. Any further thoughts?
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
next step:
select * 
from ( SELECT * FROM abc 
 UNION SELECT * FROM def 
 UNION SELECT * FROM ghi
)  sq
GROUP BY id
ORDER BY `date` DESC

Open in new window

0
Rob--Author Commented:
Thanks for the help, but this query still produced the same result
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
sorry, I should have put
GROUP BY inquiry  
instead of
GROUP BY id

if that still does not help, I need to see "data" :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rob--Author Commented:
It worked, thank you very much!
0
Rob--Author Commented:
Thorough answer, thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.