php - using joins in sql - not getting all wanted results -


i'm trying query mysql db following sql :

$sql = "     select     t1.discipline,     t4disc.color,     t4disc.naam,     t1.date_posted,     t2ploeg.naam ploegid,     t1.cat,     t1.tekst,     t3user.naam posterid,     t3user.voornaam     log_logboek_".$log." t1     join log_ploegen_".$log." t2ploeg on t1.ploegid = t2ploeg.id     join log_users t3user on t1.posterid = t3user.id     join log_disciplines t4disc on t1.discipline = t4disc.id     ". $where ."     , t1.discipline in ($vis_ids)     order date_posted asc;      ";     

this query work , gives results. problem joins if 1 of joined tables doesn't contain matching id, row gets skipped results entirely. let's say, example, user deleted log_users table, records id gets skipped in query because there no matching user t1.posterid.

is there way of joining these tables can in 1 query, , still getting row in results ? if so, can substitute missing id's in someway ?

any appreciated.

i think query want:

select t1.discipline, t4disc.color, t4disc.naam, t1.date_posted, t2ploeg.naam ploegid,        t1.cat, t1.tekst, t3user.naam posterid, t3user.voornaam log_logboek_".$log." t1 left join      log_ploegen_".$log." t2ploeg      on t1.ploegid = t2ploeg.id left join      log_users t3user      on t1.posterid = t3user.id left join      log_disciplines t4disc      on t1.discipline = t4disc.id ". $where ."t1.discipline in ($vis_ids) order date_posted asc; 

the condition in where clause on first table, filter rows accordingly. if there no matches condition, might filtered out.

if move where conditions on clause, strange thing happens left outer joins. on condition fails, row still kept in result set -- how left outer joins work.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -