SQL Join Returns null
I am trying to return some values from database
WHAT I HAVE
USERS
user_id (pk)
OWN_EVENTS
user_id (fk)
event_id(pk)
ATTENDEES
user_id (fk)
event_id(fk)
WHAT I NEED TO RETURN
I need to return all the rows in ATTENDEES that's event_id equals to some
value,status is not equal to 3 and , event_name value of that event from
OWN_EVENTS table and email value from USERS table
WHAT I HAVE TRIED I have been trying all sort of combinations but couldnt
figure out what I am doing wrong
http://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins
Even this returns null:
$query ="SELECT A1.event_name,A1.start_date
FROM ATTENDEES A1
INNER JOIN OWN_EVENTS A2 ON A2.event_id = A1.event_id
WHERE A1.event_id = $event_id";
or
$query ="SELECT A1.event_name,A1.start_date ,A3.email
FROM ATTENDEES A1
INNER JOIN OWN_EVENTS A2 ON A2.event_id = A1.event_id
INNER JOIN USERS A3 ON A3.user_id = A1.user_id
WHERE A1.event_id = $event_id AND A1.status != 3";
What query call do I need to make?
No comments:
Post a Comment