0% found this document useful (0 votes)
10 views2 pages

Mysql Joins

Uploaded by

Navya RK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Mysql Joins

Uploaded by

Navya RK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

MYSQL JOINS

A JOIN clause is used to combine rows from two or more tables, based on a related
column between them.

Supported Types of Joins in MySQL


 INNER JOIN: Returns records that have matching values in both tables
 LEFT JOIN: Returns all records from the left table, and the matched records from the
right table
 RIGHT JOIN: Returns all records from the right table, and the matched records from
the left table
 CROSS JOIN: Returns all records from both tables

INNER JOIN Syntax


SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
MySQL LEFT JOIN Keyword

The LEFT JOIN keyword returns all records from the left table (table1), and the matching
records (if any) from the right table (table2).

LEFT JOIN Syntax


SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
Note: The LEFT JOIN keyword returns all records from the left table, even if there are no
matches in the right table.

MySQL RIGHT JOIN Keyword

The RIGHT JOIN keyword returns all records from the right table (table2), and the matching
records (if any) from the left table (table1).

RIGHT JOIN Syntax


SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;

SQL CROSS JOIN Keyword


The CROSS JOIN keyword returns all records from both tables (table1 and table2).

CROSS JOIN Syntax


SELECT column_name(s)
FROM table1
CROSS JOIN table2;

create table orders (orderid integer(7),customerid integer(4), orderdate date);


create table customers (customerid integer(4),custname varchar(50),contactname
varchar(50),country varchar(20));

insert into orders values (10308,2,'1996-09-18');


insert into orders values (10309,37,'1996-09-19');
insert into orders values (10310,77,'1996-09-20');

insert into customers values(1,'Harish','Akash','germany');


insert into customers values(2,'Priyanka','Sourav','india');
insert into customers values(3,'Sumanth','Devender','usa');

You might also like