mysql - Is this query are ok? (multiple JOIN's in SQL) -


i have query:

select matches.id,  matches.player1,  matches.player2,  users.firstname firstname,  tournaments.tid tid,  users.tempsalt salt  matches  inner join tournaments  on matches.tid = tournaments.tid  inner join users  on matches.uid = users.uid  ((matches.status = 0)  or (matches.status = 1))  , (tournaments.status <> 3)  , (users.tempsalt = '324234324234') 

three tables - matches, tournaments, users

  • matches(id, tid, uid, player1, player2, status)
  • users(id, uid, firstname, tempsalt)
  • tournaments(id, tid, status)

added: matches[1,3,2,john,mark,0] [2,3,null,piter,sara,1]

users[1,3,alex,346] [2,4,sam,32423]

tournaments[1,3,2] wanna in result: [1,john,mark,sam,3,32423] , null [2,piter,sara,null,3,null]

if matches.uid null no results. want results when matches.uid null too. is possible in 1 sql query?

use left join , put conditions of joined tables in on clause

select m.id, m.player1, m.player2,         u.firstname firstname, u.tempsalt salt,        t.tid tid matches m left join tournaments t on m.tid = t.tid                         , t.status <> 3 left join users u on m.uid = u.uid                   , u.tempsalt = '324234324234' m.status in (0,1) 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -