SQL Primary Key
SQL Primary Key
“Orders" table
Query:
σ Customer_City="Agra" (CUSTOMER)
Output:
Customer_Id Customer_Name Customer_City
C10100 Steve Agra
C10111 Raghu Agra
Project Operator (∏)
• Project operator is denoted by ∏ symbol and
it is used to select desired columns (or
attributes) from a table (or relation).
• Project operator in relational algebra is similar
to the Select statement in SQL. But it will work
on columns
Syntax of Project Operator (∏)
• ∏ column_name1, column_name2, ....,
column_nameN(table_name)
Project Operator (∏) Example
• Table: CUSTOMER
Customer_Id Customer_Name Customer_City
C10100 Steve Agra
C10111 Raghu Agra
C10115 Chaitanya Noida
C10117 Ajeet Delhi
C10118 Carl Delhi
Carl
Paul
Lucy
Rick
Steve
Aditya
Steve
Paul
Lucy
Set Difference (-)
Carl
Rick
Cartesian product (X)
• Cartesian Product is denoted by X symbol.
• Lets say we have two relations R1 and R2 then
the cartesian product of these two relations
(R1 X R2) would combine each tuple of first
relation R1 with the each tuple of second
relation R2.
Syntax of Cartesian product (X)
• R1 X R2
Cartesian product (X) Example
• Table 1: R
Col_A Col_B
AA 100
BB 200
CC 300
• Table 2: S
Col_X Col_Y
XX 99
YY 11
ZZ 101
• Query:
• Lets find the cartesian product of table R and
S.
• RXS
• RXS Col_A Col_B Col_X Col_Y
AA 100 XX 99
AA 100 YY 11
AA 100 ZZ 101
BB 200 XX 99
BB 200 YY 11
BB 200 ZZ 101
CC 300 XX 99
CC 300 YY 11
CC 300 ZZ 101
Write a SQL query to fetch the count of employees working in project 'P1'.
• Ques.1. Write a SQL query to fetch the count
of employees working in project 'P1'.
• Ques.2. Write a SQL query to fetch employee
names having salary greater than or equal to
5000 and less than or equal 10000.
• Ques.3. Write a SQL query to fetch project-
wise count of employees sorted by project's
count in descending order.
• SELECT COUNT(*) FROM EmployeeSalary
WHERE Project = 'P1';