Define SQL
Define SQL
Define SQL
) Explain DDL commands in detail with an example. 5M b) Define join. Explain various types of join
with examples 10M
) Define view. Explain views in detail with example 5M b) Explain binary relational operations in
relational algebra with an example. 10M
Describe command constraints and explain insert , delete , rename commands with example
Explain any 5 data types in SQL 10m Create a table on student details and insert 5 records in it 5m
) Write SQL queries for the following given schema SALESPERSON(empid, Name, Start_year,
Dept_no) TRIP(empid, From_city, To_city, Departure_date, Return_date, Trip_id) EXPENSE(Trip_id,
Account_number, Amount) i) find the trips made by employee whose id=1001 from month of JAN to
JUNE 1025. 10m b) use create,insert and remane commands on the above table 5m
Examine the parts of a basic SQL query How can you obtain a set of tuples as the result of a query
write SQL queries for the following given schema SALESPERSON(empid, Name, Start_year, Dept_no)
TRIP(empid, From_city, To_city, Departure_date, Return_date, Trip_id) EXPENSE(Trip_id,
Account_number, Amount) i) find the trips made by employee whose id=1001 from month of JAN to
JUNE 1025. ii) find all the trip ids whose spent amount is in the range 30000 to 50000 per trip. iii)
find the total amount spent by an employee with id 1101 in the year 2015.
list SQL built in aggregate functions 5m Consider the following schema Employees(empid:
number ,empname: string ,deptid: number, managerid: number,job_id:number,salary:real,
hiredate: date) Departments(deptid:number, deptname:string, locationid: number) Jobs(jobid:
number, jobtitle: string, minsalary: real, maxsalary: real) Write SQL queries for the following i)find
the departments having maximum salary greater than 10000. ii)Compute the average salary of
each job type of each 10m
outline the importance of Union, Intersection, Minus Operstion.. 5m List different types of JOIN
operations, describe functions and procedures 10m
1 Mahesh 100
2 Suhas 200
3 Jayendra 300
Department Table
Did Dname
100 HR
Did Dname
200 TIS
SELECT E.Eid[Eid],
D.Did[Did]
D.Dname[Dname]
FROM Employee E
NATURAL JOIN
Department D
1 100 HR
2 200 TIS
3 300 HR
1 Mahesh 100
2 Suhas 200
3 Jayendra 300
Department Table
Did DName
100 HR
200 TIS
SELECT e.Eid[Eid],
e.Ename[Ename]
e.Did[Did]
d.Did[Did]
d.Dname[Dname]
FROM Employee e
CROSS JOIN
Department d
Eid EName Did Did Dname
3.Self Join
•Any table can be joined by itself as long as aeachtable reference is given different name
using table alias.
Example:
Employee Table (E)
1 Mahesh 2
2 Suhas 3
Eid Ename Mid
3 Jayendra 3
Manager Table(M)
1 Mahesh 2
2 Suhas 3
3 Jayendra 3
SELECT E.Ename[Employee],
M.Ename[Manager]
FROM Employee E
CROSS
EmployeeM
ON E.Mid=M.Eid
Employee Manager
Mahesh Suhas
Suhas Jayendra
Employee Manager
Jayendra Jayendra
4.Inner Join
•Inner Join joins two table when there is atleast one match between two tables.
Syntax:
SELECT Column_List
FROM Table1
INNER JOIN
Table 2
ON (JOIN_Condition)
Employee Table
1 Mahesh 100
2 Suhas 200
3 Jayendra 300
Department Table
Did DName
50 DEV
Did DName
100 HR
200 TIS
SELECT E.Eid[Eid],
D.Did[Did]
D.Dname[Dname]
FROM Employee E
INNER JOIN
Department D
ON E.Did=D.DeptId
1 100 HR
2 200 TIS
3 300 HR
5. Outer Join
•The join that can be used to see rows of tables that do not meet the join condition along with
rows that satisfies join condition is called as Outer Join.
a)Left Outer Join:
•A left outer join returns all the rows for which the join condition is true and returns all other
rows from the dominant table and displays the corresponding values from the subordinate
table as NULL.
Employee Table
Eid EName Did
1 Mahesh 100
2 Suhas 200
3 Jayendra 500
Department Table
Did DName
50 DEV
100 HR
200 TIS
SELECT E.Eid[Eid],
D.Did[Did]
D.Dname[Dname]
FROM Employee E
LEFT OUTER JOIN
Department D
ON E.Did=D.DeptId
Eid Did Dname
1 100 HR
2 200 TIS
3 500 NULL
1 Mahesh 100
2 Suhas 200
3 Jayendra 500
Department Table
Did DName
50 DEV
Did DName
100 HR
200 TIS
SELECT E.Eid[Eid],
D.Did[Did]
D.Dname[Dname]
FROM Employee E
RIGHT OUTER JOIN
Department D
ON E.Did=D.DeptId
1 100 HR
2 200 TIS
NULL 50 DEV
1 Mahesh 100
2 Suhas 200
3 Jayendra 500
Department Table
Did DName
50 DEV
100 HR
200 TIS
SELECT E.Eid[Eid],
E.Did[Did],
D.Did[Did],
D.Dname[Dname]
FROM Employee E
FULL OUTER JOIN
Department D
ON E.Did=D.DeptId
Eid Did Dname
1 100 HR
2 200 TIS
3 500 NULL
NULL 50 DEV
SQL join statements allow us to access information from two or more tables
at once. They also keep our database normalized. Normalization allows us
to keep data redundancy low so that we can decrease the amount of data
anomalies in our application when we delete or update a record.
A JOIN clause allows us to combine rows from two or more tables based on a
related column.
The type of join statement you use depends on your use case. There are four
different types of join operations: