crosstab query?
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.
Sorry, only registered users may post in this forum.
© 1995-2008 MySQL AB, 2008- Sun Microsystems, Inc.