YogeshChauhan.com
SQL Left Join
August 31, 2019

SQL LEFT JOIN Keyword

As per the name SQL Left join returns all the records from the left table and the similar records form the right table. Let’s take a look at the syntax:


SELECT column/columns
FROM table_left LEFT JOIN table_right
ON table_left.column= table_right.column;

As you can see in the syntax above, the query will show all the records from the table on the left side (table_left) and also the matched records form the table on the right side (table_right).

Let’s take a look at the example:


SELECT country.Region, countrylanguage.Language, country.Name, country.Code
FROM country
LEFT JOIN countrylanguage ON country.Code=countrylanguage.CountryCode ORDER BY Code LIMIT 10;

In the example above, I am selecting the columns Region, Name and Code form country table and Language from countrylanguage table. As I’ve discussed before the table on the left side will have it’s all records pulled up and displayed, which in this example, is country table. Then the query watches out for the similar records in  both the tables and then displays those records from the tables.

If the records are exactly matching from all the columns requested then it will only display single entry otherwise there will be multiple lines of display. For example, lets say the language is different for matching records for AFG country code. Then it will create a row with all the records form left column and then create one more row for the matching records with entries from the right table.

I’ve set the LIMIT 10 as both of tables have approx. 100 lines of records.

dreamhost

Leave a Reply

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to set opacity or transparency using CSS? #3 Pagination in CSS with multiple examples #4 How to make HTML form interactive and using CSS? #5 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

Mar 3 How to embed YouTube or other video links in WordPress? Mar 3 How to change the Login Logo in WordPress? Mar 3 substring() Method in JavaScript Mar 3 Window setInterval() Method in JavaScript Mar 2 How to zoom an element on hover using CSS? Mar 2 the box-sizing property in CSS

You might also like these

How to add a ribbon on top of a container using CSS?CSSHow to Hide HTML elements automatically after few seconds using JavaScript?HTMLHow to get start index and end index (as int) of substring in Swift?SwiftPostgreSQL BETWEENPostgresHow to create a horizontal scrolling menu with and without flex using CSS (or SCSS)?CSSGeneral concepts in DrupalDrupal