colap Posted August 21, 2015 Share Posted August 21, 2015 (edited) http://www.sitepoint.com/understanding-sql-joins-mysql-database/ Is it possible to see the result of left join of two tables(without on clause)? mysql> select * from user; +----+----------+--------+ | id | name | course | +----+----------+--------+ | 1 | Alice | 1 | | 2 | Bob | 1 | | 3 | Caroline | 2 | | 4 | David | 5 | | 5 | Emma | NULL | +----+----------+--------+ 5 rows in set (0.00 sec) mysql> select * from course; +----+------------+ | id | name | +----+------------+ | 1 | HTML5 | | 2 | CSS3 | | 3 | Javascript | | 4 | PHP | | 5 | MySQL | +----+------------+ 5 rows in set (0.00 sec) mysql> SELECT * FROM `user` left join course on user.course=course.id; +----+----------+--------+------+-------+ | id | name | course | id | name | +----+----------+--------+------+-------+ | 1 | Alice | 1 | 1 | HTML5 | | 2 | Bob | 1 | 1 | HTML5 | | 3 | Caroline | 2 | 2 | CSS3 | | 4 | David | 5 | 5 | MySQL | | 5 | Emma | NULL | NULL | NULL | +----+----------+--------+------+-------+ 5 rows in set (0.00 sec) Why/how is id=NULL and name=NULL for Emma,NULL? Edited August 21, 2015 by php-coder Quote Link to comment https://forums.phpfreaks.com/topic/297882-is-it-possible-to-see-the-result-of-left-join-of-two-tables/ Share on other sites More sharing options...
Barand Posted August 21, 2015 Share Posted August 21, 2015 (edited) Because there is no record in course table where the course.id matches the user.course for Emma in the user table Edited August 21, 2015 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/297882-is-it-possible-to-see-the-result-of-left-join-of-two-tables/#findComment-1519379 Share on other sites More sharing options...
Psycho Posted August 21, 2015 Share Posted August 21, 2015 What do you mean by "Is it possible to see the result of left join of two tables(without on clause)?" What do you expect to get without an ON clause for a LEFT/RIGHT JOIN? Why don't you explain what you are trying to achieve? Quote Link to comment https://forums.phpfreaks.com/topic/297882-is-it-possible-to-see-the-result-of-left-join-of-two-tables/#findComment-1519385 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.