Infolinks

Breaking

Adsense

Wednesday, January 20, 2016

SQL JOIN: Display Records With or Without Match on The Other Table

Good day! I have new article for you related to joining tables using SQL query. There are several types of joins that combines two or more tables to retrieve data from multiple tables. I already created an article for the NATURAL JOIN. This time, it will be about the use of the EQUIJOIN. Here, you will know how to distinguish and use LEFT and RIGHT join. You might encounter different joins but select what's suitable base on your needs.

Equijoin or inner join, Natural join, Non-equijoin, Outer join, Self join are the different types of joins used in SQL query.

The LEFT JOIN is used to join two or more tables and return all records on the left table that has match or even without match on the right table. While the RIGHT JOIN is used to join two or more table and will return all records from the right table with or without match on the left table. 

There will be cases where you want to join two (2) table and display records that has match or even without match on the other table.
Table
STUDENT



GRADES







Refer on the table above. 
Query
SELECT * FROM student left join grade on student.stud_id=grade.stud_id

If you want to display all students even without grades, then you can use SQL LEFT JOIN or RIGHT JOIN.  The LEFT JOIN will display all records on the left table even without match on the right table. The RIGHT JOIN will display all records on the right table even without a match on the left table.

Output for RIGHT JOIN





Hope this helps! Good day! ^_^

SQL JOIN: Display Records With or Without Match on The Other Table

No comments:

Post a Comment

Adbox