noobdvlpr — 2014-05-08T16:19:41-04:00 — #1
hey guys so im really struggling with selecting data from 3 tables
so what ive tried to do is:
SELECT c.id,c.name,g.id,g.event_id,e.event_id FROM contact c INNER JOIN guest g ON g.id = c.id LEFT JOIN event e ON g.event_id = e.event_id
but no data appears nor any errors or notices or warning.
i want to get c.name and c.id from contact where c.id = g.id and where e.event_id = g.event_id(i need this coz im using a drop down list to select the names and display, the drop down list is populated by event_name)
mawburn — 2014-05-08T16:24:25-04:00 — #2
Are Contact ID and Guest ID the foreign keys? I'm not seeing anything wrong with your SQL, so the only thing I can think of is they aren't matching.
wolfshade — 2014-05-08T16:25:23-04:00 — #3
LEFT OUTER JOIN will get all data from the left table and only associated data from the right table. If there is nothing in "guest" associated with records in "contact" you'll still get data from "contact".
noobdvlpr — 2014-05-08T22:37:55-04:00 — #4
i got it. sorry guys, it had smtg to do with the ajax not the query. blush thanks though. at least i know im doing my query correctly.
mawburn — 2014-05-08T23:01:50-04:00 — #5
No worries. Always remember to test your SQL on your server before thinking that's the issue.