php - SQL Join Returns null -


i trying return values database

what have

users

user_id (pk)

enter image description here

own_events

user_id (fk)

event_id(pk) enter image description here

attendees

user_id (fk)

event_id(fk)

enter image description here

what need return

i need return rows in attendees that's event_id equals value,status not equal 3 , , event_name value of event own_events table , email value users table

what have tried have been trying sort of combinations couldnt figure out doing wrong http://www.codeproject.com/articles/33052/visual-representation-of-sql-joins

even returns null:

$query ="select a1.event_name,a1.start_date                       attendees a1                       inner join own_events a2  on  a2.event_id = a1.event_id                     a1.event_id = $event_id"; 

or

$query ="select a1.event_name,a1.start_date ,a3.email                  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                 a1.event_id = $event_id , a1.status != 3"; 

what query call need make?

edit::::: sample data:

attendees

enter image description here

ownevents

enter image description here

users

enter image description here

the problem join users table. joining attendees. however, think want owner email.

this switches joins left outer join. return matching rows in attendees table, when there no matches in other tables:

select oe.event_name, a.start_date, u.email  attendees left outer join       own_events oe      on oe.event_id = a.event_id left outer join      users u      on a.user_id = u.user_id a.event_id = $event_id , a.status <> 3 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -