PDA

View Full Version : SQL query to select username and certain profile fields?


LadyBeth
11-26-2013, 06:43 PM
I need to run a query to select the username and certain custom profile field IDs in a list? I can do that for the usernames but am not sure how to pull in the other data.

Can someone help me out?

mokujin
11-26-2013, 07:54 PM
SELECT *
FROM user AS user
LEFT JOIN profilefield AS profilefield ON (user.userid=profilefield.userid)

LadyBeth
11-27-2013, 09:21 PM
Hi, I get this response:
#1054 - Unknown column 'profilefield.userid' in 'on clause'

In the profilefield table there isn't a userid column.

kh99
11-27-2013, 09:29 PM
Edit: see Lynne's answer below.

Lynne
11-27-2013, 09:44 PM
I don't know that you really want the profilefield table. That is the table that saves the profilefield information that the admin inputs to create the profilefields. When the user fills out a profilefield, his information is stored in the userfield table. So...

SELECT username, fieldX, fieldY, fieldZ
FROM user LEFT JOIN userfield ON(user.userid=userfield.userid)

kh99
11-27-2013, 10:17 PM
Lynne is right of course. I even looked at the database to make sure I was getting the right table, then spaced out and used profilefield instead. :o

Lynne
11-28-2013, 02:48 AM
LOL Kevin. The only reason I knew was because I had a question about that recently and I also thought it was the profilefield table until I looked it up and realized otherwise. :)

LadyBeth
12-03-2013, 08:16 PM
Thank you, that worked.