Skip navigation links

MySQL Forums :: Newbie :: crosstab query?


Advanced Search

crosstab query?
Posted by: Mike Clark ()
Date: November 03, 2009 10:13AM

So I'm not sure if this is what this type of query is called, but the info on crosstab queries seems to be the closest to what I need...but I still can't figure this out. Any help would be greatly appreciated. Here's what I have:

tbl_users

user_id | user_name
-----------------------
1 | user1
2 | user2
3 | user3
4 | user4


tbl_data

data_id | user_id | data_date
-----------------------------------
1 | 1 | 2008-01-14
2 | 1 | 2009-05-22
3 | 1 | 2009-07-12
4 | 2 | 2009-08-08
5 | 3 | 2009-01-13
6 | 3 | 2009-09-10

(maximum of three entries per user)


What to get this for a result:

user_name | date1 | date2 | date3
-------------------------------------------------------------
user1 | 2008-01-14 | 2009-05-22 | 2009-07-12
user2 | 2009-08-08 | null | null
user3 | 2009-01-13 | 2009-09-10 | null
user4 | null | null | null


Just can't figure out how to do this with one query. Thanks in advance for the help!



Edited 1 time(s). Last edit at 11/03/2009 10:20AM by Mike Clark.

Options: ReplyQuote


Subject Written By Posted
crosstab query? Mike Clark 11/03/2009 10:13AM
Re: crosstab query? Peter Brawley 11/03/2009 10:20AM
Re: crosstab query? laptop alias 11/03/2009 10:31AM
Re: crosstab query? Mike Clark 11/03/2009 10:54AM
Re: crosstab query? laptop alias 11/03/2009 11:01AM
Re: crosstab query? Mike Clark 11/03/2009 11:04AM


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.