1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Help with joins please?

Discussion in 'Web Design & Development' started by colinsp, Jan 14, 2011.

Thread Status:
Not open for further replies.
  1. colinsp

    colinsp Thread Starter

    Joined:
    Sep 5, 2007
    Messages:
    2,272
    First Name:
    Colin
    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.
     
  2. DrP

    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.
     
  3. colinsp

    colinsp Thread Starter

    Joined:
    Sep 5, 2007
    Messages:
    2,272
    First Name:
    Colin
    Brilliant,(y) thanks very much that works perfectly.:)
     
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 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/974653

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice