0% found this document useful (0 votes)
3 views3 pages

SQL Joins

The document explains various types of SQL joins, including Inner, Left, Right, Full, Cross, and Self joins, along with their syntax and examples. It also covers the concepts of Indexes, which enhance data search speed, and Views, which provide a security mechanism for accessing table data. Each join type is described in terms of the data it retrieves from related tables.

Uploaded by

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

SQL Joins

The document explains various types of SQL joins, including Inner, Left, Right, Full, Cross, and Self joins, along with their syntax and examples. It also covers the concepts of Indexes, which enhance data search speed, and Views, which provide a security mechanism for accessing table data. Each join type is described in terms of the data it retrieves from related tables.

Uploaded by

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

SQL Joins:

The join clause allows us to retrieve data from two or more related tables

Types of Joins:

1.Inner join 2.Left(outer) join 3.Right(outer) join 4.full(outer) join


5.Cross join 6.Self Join

1.Inner join

Inner Join Returns the rows(records) that have matching data in both tables

SELECT column_name(s) FROM table1 INNER JOIN table2 on


table1.column_name = table2.column_name;

select * from mobiles inner join accessories on mobiles.sid=accessories.ano;

2.Left join

Left join Returns all records from the left table, and the matched records
from the right table

SELECT column_name(s) FROM table1 LEFT JOIN table2


on table1.column_name = table2.column_name;

select * from mobiles left join accessories on mobiles.sid=accessories.ano;

3.Right join

Right join Returns all records from the right table, and the matched records
from the left table

SELECT column_name(s) FROM table1 RIGHT JOIN table2


ON table1.column_name = table2.column_name;

select * from mobiles right join accessories on mobiles.sid=accessories.ano;

4.Full join

Full join Returns all records from both tables where there is a match in either
left or right table. If there is no match it will show null values(blank)

Full join is not supported with mysql database.


Syntax:
SELECT column_name(s) FROM table1 FULL JOIN table2 ON table1.column
name = table2.column name;

5.Cross Join:

The cross join returns all records from both tables (table1 and table2) whether
the other table matches or not.
Cross join produces a Cartesian product of the two tables.
Syntax:
SELECT column_name(s) FROM table1 CROSS JOIN table2;
Ex:
Select * from mobiles cross join accessories;

6.Self Join:

self join is a type of join where a table is joined with itself. This allows to
compare rows within the same table.

Syntax:
SELECT column_name(s) FROM table_name aliasname1
JOIN table_name aliasname2 ON aliasname1.column_name =
aliasname2.column_name;

Ex:
select * from mobiles t1 join mobiles t2 on t1.mid=t2.mid;

Index:

Index is mainly used to speed up the searching of data in the database table.

Syntax:

Create index indexname on tablename(column names);

Example:
Create index myindex on mobiles(sid);

View:
Views can be used as security mechanism by letting users access the table data
without granting the permission to the tables

Syntax:
create view viewname as select column names from tablename;

Example:
create view myview as select id,name,salary,bonus,tax,department from
employees;

select * from myview;

You might also like