Solved: Help with joins please?

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

colinsp

Colin
Thread Starter
Joined
Sep 5, 2007
Messages
2,324
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.
 

DrP

Joined
Jul 23, 2005
Messages
739
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.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top