Tech Support Guy banner
  • Please post in our Community Feedback thread for help with the new forum software! If you are having trouble logging in, please Contact Us for assistance.
Status
Not open for further replies.
1 - 3 of 3 Posts

·
Registered
Joined
·
2,389 Posts
Discussion Starter · #1 ·
Can someone help me with creating a mysql query please?

I have a table called attendees with the following fields
id, fname, lname, city

I have a second table called answers with the following fields
registration_id, question_id,answer

There are 3 rows in the answers table per id. I cannot alter these tables as they are part of another application I just need to extract some of the data onto a web page for a custom report that is not available in the application.

id and registration_id are the common link between the tables

I want to create a query that gives me

fname, lname, city and answer where question_id = 3

I have spent all day trying this with left joins, inner joins, joins and right joins without success, so I suspect that I am missing something simple or that I shouldn't be using a join at all. Maybe I should just use 2 queries but I suspect that this will be inefficient.

Any help or suggestions most welcome.
 

·
Registered
Joined
·
739 Posts
Try this:

Code:
SELECT fname, lname, city, answer FROM attendees LEFT JOIN answers ON attendees.id=answers.registration_id WHERE question_id = '3'
If you have access to PhpMyAdmin, it might be worth trying to run the query in that before calling it with PHP? It can be a lot quicker if troubleshooting a MySQL query.
 
1 - 3 of 3 Posts
Status
Not open for further replies.
Top