Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: SQL Query

SQL Query 13 years 7 months ago #13577

  • marcporter
  • marcporter's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 23
  • Thank you received: 0
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.

Thanks in advance.

Please Log in or Create an account to join the conversation.

SQL Query 13 years 7 months ago #13601

  • suyog
  • suyog's Avatar
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 41
  • Thank you received: 0
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

Please Log in or Create an account to join the conversation.

SQL Query 13 years 7 months ago #13608

  • marcporter
  • marcporter's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 23
  • Thank you received: 0
You are a life saver thank you very much!

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.196 seconds