Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learn SQL using MySQL in One Day and Learn It Well

You're reading from  Learn SQL using MySQL in One Day and Learn It Well

Product type Book
Published in Apr 2024
Publisher Packt
ISBN-13 9781836205678
Pages 121 pages
Edition 1st Edition
Languages
Author (1):
Jamie Chan Jamie Chan
Profile icon Jamie Chan

Joins

 

Let’s start with joins.

 

Like the name suggests, a join is used to join data from different tables based on a related column between the tables.

 

The syntax for joining two tables is:

 

SELECT [table_names.]columns_names_or_other_information

FROM

left_table

JOIN / INNER JOIN / LEFT JOIN / RIGHT JOIN

right_table

ON

left_table.column_name = right_table.column_name;

 

There are three main types of joins in mySQL: inner join, left join and right join. These are represented by the Venn diagrams below: ImageTo demonstrate the difference between them, let’s consider the following two tables:

 

Image

Here, we have two tables called one and two.

 

You can see that column A in table one shares some common values with column C in table two. We can join the two tables using these two columns.

 

If we do an inner join, we write

 

SELECT A, C, one.B AS 'one B', two.B AS 'two B'

FROM

one

INNER...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}