mysql - How does Left Join / IS NULL eliminate records which are there in one table and not in the other? -


i having tough time understand why left join / is null eliminate records there in 1 table , not in other. here example

select  l.id, l.value    t_left l left join t_right r on      r.value = l.value   r.value null 

why should r.value = null eliminate records ? not understanding . know missing basic @ present cant figure out basic one. appreciate if explains me in detail .

i want basic explanation.

this explained following

mysql> select * table1 ; +------+------+ | id   | val  | +------+------+ |    1 |   10 | |    2 |   30 | |    3 |   40 | +------+------+ 3 rows in set (0.00 sec)  mysql> select * table2 ; +------+------+ | id   | t1id | +------+------+ |    1 |    1 | |    2 |    2 | +------+------+ 2 rows in set (0.00 sec) 

here table1.id <-> table2.t1id

now when left join joining key , if left table table1 data table1 , in non-matching record on table2 set null

mysql> select t1.* , t2.t1id table1 t1  left join table2 t2 on t2.t1id = t1.id ; +------+------+------+ | id   | val  | t1id | +------+------+------+ |    1 |   10 |    1 | |    2 |   30 |    2 | |    3 |   40 | null | +------+------+------+  3 rows in set (0.00 sec) 

see table1.id = 3 not have value in table2 set null when apply condition further filtering

mysql> select t1.* , t2.t1id table1 t1  left join table2 t2 on t2.t1id = t1.id t2.t1id null; +------+------+------+ | id   | val  | t1id | +------+------+------+ |    3 |   40 | null | +------+------+------+ 1 row in set (0.00 sec) 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -