Can someone help me with a sql query? I am very new to sql, I want to query some specific data on registrations.
I have done the following,
SELECT jos_dtregister_user_field_values.value FROM jos_dtregister_user INNER JOIN jos_dtregister_user_field_values ON jos_dtregister_user.userid=jos_dtregister_user_field_values.user_id WHERE jos_dtregister_user_field_values.field_id=16
This will pull the first Name (field id 16) but I can't figure out how to continue the query to also get other fields and put them in columns. All of the user data is in a single column, jos_dtregister_user_field_values.value. If each field was in a separate column instead of a separate row, I think I could figure out the query.
You can use
SELECT X.groupMemberId, B.title,
MAX(CASE WHEN A.field_id = 48 THEN value END) AS FIRSTNAME,
MAX(CASE WHEN A.field_id = 49 THEN value END) AS LASTNAME,
MAX(CASE WHEN C.field_id = 58 THEN value END) AS ORGANIZATION,
MAX(CASE WHEN C.field_id = 50 THEN value END) AS ADDRESS,
MAX(CASE WHEN C.field_id = 51 THEN value END) AS ADDRESS2,
MAX(CASE WHEN C.field_id = 52 THEN value END) AS CITY,
MAX(CASE WHEN C.field_id = 53 THEN value END) AS STATE,
MAX(CASE WHEN C.field_id = 54 THEN value END) AS ZIP,
FROM ` jos_dtregister_group_member` AS X
INNER JOIN ( SELECT * FROM jos_dtregister_member_field_values) AS A ON X.groupMemberID = A.member_id
INNER JOIN ( SELECT * FROM jos_dtregister_group_event) AS B ON X.eventId = B.slabId
INNER JOIN ( SELECT * FROM jos_dtregister_group_amount) AS C ON X.userID = C.groupId
GROUP By X.userID