DBMS
DBMS
No:
Page No.:
Date:
Left Join:
Left Join retrieves all the records and the data from the left table and all matching records from
the right table.
Here, the “LEFT JOIN” keyword is used.
In Left Join it returns rows from both tables and all the rows from the left table.
Syntax:
SELECT columns
FROM left_table
LEFT JOIN right_table ON
join_condition;
Right Join:
Right Join retrieves all the records and the data from the right table and all matching records
from the left table.
Here, the “RIGHT JOIN” keyword is used.
In Right Join it returns rows from both tables and all rows from the right table.
Syntax:
SELECT columns
FROM left_table
RIGHT JOIN right_table ON
join_condition;
Syntax:
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
Full Join:
The FULL OUTER JOIN keyword returns all records when there is a match in left (table1) or right
(table2) table records.
FULL OUTER JOIN and FULL JOIN are the same.
Syntax:
SELECT column_name
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name
WHERE condition;
select d.dname, e.eid, e.ename, e.did from dept d inner join emps e on d.did=e.did;
select d.dname, e,eid, e,ename, e.did from dept d left join emps e on d.did=e.did;
select d.dname, e.eid, e.ename, e.did from dept d full join emps e on d.did=e.did;
Sub-Queries:
1. Scalar Subqueries:
A scalar subquery returns a single value (one row and one column).
Often used in the WHERE clause to filter results based on aggregated values.
Syntax:
SELECT column_name
FROM table_name
WHERE expression operator (SELECT single_column FROM subquery);
4. Correlated Subqueries:
Reference columns from the outer query within the subquery.
The subquery execution depends on the outer query.
Program :
Lets get the data from tow tables namely employee,empid;
Correlated subqueries