Dreevoo.com | Online Learning and Knowledge Sharing
 
Home | Programs | Programming languages | PHP & MySQL | Using Inner, Left in Right Join in SQL
Guest
Click to view your profile
Topics
Programs
Languages
Recipes
Home
Shortcuts
 
 

Using Inner, Left in Right Join in SQL

Select database queries with Inner, Left and Right Join represent an important part of SQL syntax and come in very handy when you want to make more advanced queries.

 
  Author: podtalje | Version: # | 15th November 2013 |  
 
 
1.
 

Simple queries were described in previous lesson



In this lesson we will learn how to make queries using Inner, Left in Right Join.

For the purpose of this lesson we will again use tables my_table and country.

To see the complete structure of database please see the lesson mentioned above.

 
 
2.
 

So far we have learned that we can get data from two tables if we use select and match the fields in both tables.

SELECT *
FROM my_table AS a, country AS b
WHERE a.id_country = b.id

Instead of this we can also use 
INNER JOIN which is just another syntax for the example above. The logic behind this is the same and that is why also the end result will be the same.

SELECT *
FROM my_table AS a
INNER JOIN 
country AS b
ON 
a.id_country = b.id

 
 
3.
 

Of course we can add additional conditions at the end of the SQL statement also in this case by using keyword WHERE.

SELECT * FROM
my_table AS a
INNER JOIN country AS b
ON a.id_country = b.id
WHERE b.name = 'Japan'

 
 
4.
 

In the example above we are matching  a.id_country = b.id. 

The problem here is that if there is no match, there will be no returned data.

If we want to see the data from first table even if there is no match in second table, we need LEFT JOIN.

SELECT * FROM
my_table AS a
LEFT JOIN country AS b 
ON  a.id_country = b.id

This will return all the records from my_table. If there will be no match for field id, we will still get the records, just missing values will be empty (NULL).

 
 
5.
 

Similar logic also applies to RIGHT JOIN

In this case the query will return all the records from second table even if there is no match in the first table.

SELECT * FROM
my_table AS a
RIGHT JOIN country AS b 
ON  a.id_country = b.id


The main idea behind this is that by using LEFT and RIGHT JOIN we can make sure that we will always get all the data.

 
 
 
   
  Please login to post a comment
  Click to open user profile  
thefansbuzz, 19th Feb 2023, 7:32 PM
Cheap SMM Panel Social Media Marketing is a huge field with a lot of competition. If you want to stand out from the crowd, you need to know how to find ways to make your content go viral. If you are interested in using social media to market your product, this service is perfect for you. The panel gives you access to hundreds of different social media sites, so that you can find new ways to market your business. Visit our website at: https://thefansbuzz.com/
 
 
  Click to open user profile  
jimkaley, 13th Aug 2025, 10:44 AM
In SQL, LEFT JOIN and RIGHT JOIN are powerful tools for combining data from two or more tables based on a related column, allowing you to perform more advanced queries. https://www.luminartechnolab.com/ These joins are essential when working with datasets where some records might not have corresponding matches in the related table, enabling you to include incomplete or unmatched data in your results without losing context.
 
 
  Click to open user profile  
kawsar, 28th Oct 2025, 4:43 PM
Mr. Kebab Restaurant, with a pleasant and intimate atmosphere, prepares the best kebabs and northern dishes with fresh and high-quality ingredients for you to have a short trip to the lush north. Don't miss the sour kebab and baqali-qatoq and experience the best restaurant in Karaj: https://aghayekabab.com/aghaye-kabab-bes....
 
 
  Click to open user profile  
ampselectric, 13th Feb 2026, 6:41 AM
AMPS Electric Trading is a well-established electrical, automation, and industrial solutions supplier based in Doha, Qatar. The company is recognized as one of the largest and most reputed distributors and wholesalers of electrical, electronics, and automation products in the country, supporting a wide range of industries including manufacturing, construction, oil & gas, utilities, commercial buildings, and hospitality sectors.https://ampsqr.com/

 
 
  Click to open user profile  
abbaskhan8008, 15th Feb 2026, 6:52 PM
Creating the perfect playlist is an art form, and what better way to add some flair than with a hilarious playlist name? This collection of funny playlist names will have you giggling as you curate your musical masterpieces. Whether you’re looking for a laugh for your country jams, sad songs, or indie vibes, you’ve come to the right place.
 
 
  Click to open user profile  
David parker, 26th Feb 2026, 5:07 PM
Activating a Smart SIM is a straightforward verification process that links your number to authenticated personal details. It enhances security, minimizes the risk of misuse, and keeps your mobile services running without disruption. After activation, you can enjoy reliable connectivity, smooth communication, and consistent internet access every day.
https://smartsimregistrationph.com/activate-smart-sim/

 
 
  Click to open user profile  
fnfunkin, 27th Feb 2026, 3:51 AM
FNF https://fnf.lol is an extremely accessible game with gameplay revolving around only four basic arrow keys, yet it's incredibly addictive. Whether you're a beginner or a rhythm expert, you'll find joy in conquering musical notes from slow to super-fast speeds.

 
 
  Click to open user profile  
Azeron, 27th Feb 2026, 6:26 PM
] @w-lg/main:[--thread-content-margin:--spacing(16)] px-(--thread-content-margin)">
In Japanese, purple is known as “murasaki” (紫), a color long associated with elegance and prestige. Historically linked to the imperial court and high-ranking nobles, murasaki symbolized refinement, wisdom, and spiritual depth. Even today, purple in Japanese culture carries a sense of creativity and quiet luxury, blending tradition with modern expression.
https://alljapanesenames.com/japanese-na....
 
 
  Click to open user profile  
peter andrew, 28th Feb 2026, 4:46 PM
] @w-lg/main:[--thread-content-margin:--spacing(16)] px-(--thread-content-margin)">
Names that mean time often carry a sense of destiny and quiet strength. Names like Chronos and Kairos reflect different sides of time—one steady and continuous, the other rare and perfectly timed. Zaman and Era symbolize the flow of life and the passing of generations. Choosing a name connected to time can represent patience, growth, and the belief that every moment holds meaning.
https://allnameslab.com/japanese-names-t....
 
 
  Click to open user profile  
peter andrew, Tuesday, 17th Mar 2026, 4:30 PM
SillyNamers is a fun and creative platform where unique and funny name ideas come to life. It helps you discover playful usernames, quirky nicknames, and catchy names that stand out and bring a smile.
https://sillynamers.com/
 
   
 
 
online learning made for people
Dreevoo.com | CONTRIBUTE | FORUM | INFO