Week-1a Intro Database
Week-1a Intro Database
JOINS
1-INNER JOIN
2-LEFT OUTER JOIN
3-RIGHT OUTER JOIN
4-FULL OUTERJOIN
DISTINCT
SET OPERATORS
1-UNION
2-INTERSECT
3-MINUS
DISTINCT : IT IS USED TO LIST UNIQUE VALUES.
SET OPERATORS
1-UNION 2-INTERSECT 3-MINUS
A INTERSECT B
A UNION B
A MINUS B
B MINUS A
UNION and UNION ALL
UNION
The UNION command is used to select related information from two tables, much
like the JOIN command. However, when using the UNION command all selected
columns need to be of the same data type.
Note: With UNION, only distinct values are selected. (NO DUPLICATED VALUE)
Economy Engineering
ID NAME ID NAME
01 AYNUR 01 SERIK
02 GULNUR 02 BERIK
03 NURGUL 03 YERIK
04 SERIK 04 NURIK
Economy Engineering
ID NAME ID NAME
01 AYNUR NAME 01 SERIK
02 GULNUR AYNUR 02 BERIK
03 NURGUL GULNUR 03 YERIK
04 SERIK NURGUL 04 NURIK
SERIK
BERIK
Economy Engineering YERIK
NURIK
AYNUR
NURIK 7 rows selected
YERIK
GULNUR SERIK
BERIK
NURGUL
SELECT NAME FROM ECONOMY
UNION
SELECT NAME FROM ENGINEERING
UNION ALL
The UNION ALL command is equal to the UNION command, except that UNION
ALL selects all values.
Economy Engineering
ID NAME ID NAME
01 AYNUR 01 SERIK
02 GULNUR 02 BERIK
03 NURGUL 03 YERIK
04 SERIK 04 NURIK
NAME
AYNUR
GULNUR
SELECT NAME FROM ECONOMY
NURGUL
UNION ALL SERIK
BERIK
SELECT NAME FROM ENGINEERING
YERIK
NURIK
8 rows selected
INTERSECT
The INTERSECT command is used to select the same values from two tables.
Economy Engineering
ID NAME ID NAME
01 AYNUR 01 SERIK
02 GULNUR 02 BERIK
03 NURGUL 03 YERIK
04 SERIK 04 NURIK
Economy Engineering
SELECT NAME FROM ECONOMY
AYNUR
NURIK INTERSECT
YERIK SELECT NAME FROM ENGINEERING
GULNUR SERIK
BERIK NAME
NURGUL SERIK
1 rows selected
MINUS
The MINUS command is used select all distinct rows selected by the first table but
not by the second table.
Economy Engineering
ID NAME ID NAME
01 AYNUR 01 SERIK
02 GULNUR 02 BERIK
03 NURGUL 03 YERIK
04 SERIK 04 NURIK
AYNUR MINUS
NURIK
SELECT NAME FROM ENGINEERING
YERIK
GULNUR SERIK NAME
BERIK AYNUR
NURGUL GULNUR
NURGUL
3 rows selected
NAME
SELECT NAME FROM ECONOMY AYNUR
MINUS GULNUR
NAME
SELECT NAME FROM ENGINEERING
NURIK
MINUS
YERIK
SELECT NAME FROM ECONOMY
BERIK
3 rows selected
GROUP BY
TABLE : CELLS
Company Month Members
KCELL JANUARY 5
KCELL FEBRUARY 3
DALACOM JANUARY 4
DALACOM FEBRUARY 5
BEELINE JANUARY 3
BEELINE FEBRUARY 2
Company Members
KCELL 8 Month Members
DALACOM 9 JANUARY 12
FEBRUARY 10
BEELINE 5
HAVING
TABLE : CELLS
Company Month Members
KCELL JANUARY 5
KCELL FEBRUARY 3
DALACOM JANUARY 4
DALACOM FEBRUARY 5
BEELINE JANUARY 3
BEELINE FEBRUARY 2
7-Display the maximum, minimum,sum, and average salary for each job type.
8-Write a query to display the number of people with the same job.
9-Determine the number of managers without listing them. Label the column “Number of Managers”
10-Write an SQL statement that will display the difference between the highest and lowest salaries.
Label the column “Diffrenece”
11-Display the manager number and salary of the lowest paid employee for the manager.
Exclude anyone where the manager id is knot known.
Exclude any groups where the minimum salary is less than $1000. Sort the output in
Descending order of salary
12-Write a query to display the department name, location name, number of employees, and the
Average of salary for all employees in that department.
Label the columns dname,loc,Number of people, and Salary , respectively.
13-List DEPTNO exists in DEPT but not in EMP.