This sql query should be simple...
August 2, 2007 9:41 PM
Subscribe
I'm trying to merge simple contact data from a bunch of single tables into one big text (csv) dump. The problem is that not all fields are present for each user. e.g. one user may be missing an email. Because of the missing field, my current (big and ugly) sql query will not return all the rows.
This seems like a simple problem, but I'm stuck. Help!
Here's a simplified version of what I've got:
table: users
columns: uid, username
data: 1, bill
data: 2, joe
table: profile_fields
columns: fid, name
data: 1, Phone
data: 2, email
table: profile_values
columns: uid, fid, value
data: 1, 1, 555-1212
data: 2, 1, 999-0000
data: 2, 2, foo@foo.com
What I want my query to output:
uid, username, phone, email
1, bill, 555-1212,
2, joe, 999-0000, foo@foo.com
(notice there is no email for uid 1)
What is the sql to do this? btw, i'm using mysql.
posted by kamelhoecker to computers & internet (13 comments total)
posted by sanko at 10:09 PM on August 2, 2007