MySQL Forums
Forum List  »  Newbie

Re: Pulling my hair out with this query
Posted by: Aziz
Date: August 11, 2005 04:10PM

It's very easy if you have MySQL 4.1 which permits the use of sub-queries, like so:

"SELECT DISTINCT NAME,
(SELECT TEST1 FROM mydata AS m2 WHERE m2.YEAR = 2002 AND m2.NAME = m1.NAME) AS '2002',
(SELECT TEST1 FROM mydata AS m2 WHERE m2.YEAR = 2003 AND m2.NAME = m1.NAME) AS '2003',
(SELECT TEST1 FROM mydata AS m2 WHERE m2.YEAR = 2004 AND m2.NAME = m1.NAME) AS '2004',
FROM mydata AS m1 ORDER BY NAME"

I hope it works.

Regards,
Aziz

Options: ReplyQuote


Subject
Written By
Posted
Re: Pulling my hair out with this query
August 11, 2005 04:10PM


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.