0% found this document useful (0 votes)
7 views5 pages

Basic Retreival Queries in SQL

The document provides various SQL retrieval queries for extracting employee and project information from a database. It includes examples of selecting specific attributes, handling ambiguous attribute names, using aliases, and performing operations like UNION and DISTINCT. Additionally, it demonstrates pattern matching and the use of arithmetic operators in SQL queries.

Uploaded by

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

Basic Retreival Queries in SQL

The document provides various SQL retrieval queries for extracting employee and project information from a database. It includes examples of selecting specific attributes, handling ambiguous attribute names, using aliases, and performing operations like UNION and DISTINCT. Additionally, it demonstrates pattern matching and the use of arithmetic operators in SQL queries.

Uploaded by

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

Basic retreival queries in SQL

 Select from where clause(syntax)


Q0. Retreive the birth date and address of the employees whose
name is ‘John B Smith’
SELECT bdate, Address
FROM EMPLOYEE
WHERE Fname=’John’ AND Minit=’B’ AND Lname=’Smith’;
Q1. Retreive the name and address of all employees who work for
‘Research’ department.
SELECT Fname,Lname, Address
FROM EMPLOYEE, DEPARTMENT
WHERE Dname=’Research’ AND Dnumber=Dno;
Q2. For every project located in ‘Stafford’,list the project
number,the controlling department number, and the department
managers last name, address and birth date.
SELECT Pnumber.Dnum,Lname, Address, Bdate
FROM PROJECT ,DEPARTMENT, EMPLOYEE
WHERE Dnum=Dnumber AND Mgr_ssn = Ssn AND
Plocation=’stafford’
Ambiguous attribute names, Aliasing, Renaming and tuple variables
Q1A. SELECT Fname, EMPLOYEE.Name, Address
FROM EMPLOYEE, DEPARTMENT
WHERE DEPARTMENT.Dname=’Research’ AND
DEPARTMENT.Dnumber= EMPLOYEE.Dno;

Q1’. SELECT Fname, EMPLOYEE.LName, EMPLOYEE.Address


FROM EMPLOYEE, DEPARTMENT
WHERE DEPARTMENT.Dname=’Research’ AND
DEPARTMENT.Dnumber= EMPLOYEE.Dno;

Q8. For each employee , retreive the employees first and last name
and the first and last name of his or her immediate supervisor.
SELECT E.Fname, E.Lname, S.Fname, S.Lname
FROM EMPLOYEE AS E, EMPLOYEE AS S
WHERE E.Super_ssn= S.ssn;

Q1B: SELECT E.Fname, E.Lname, E.Address


FROM EMPLOYEE AS E, DEPARTMENT AS D
WHERE D.Dname=’Research’ AND
D.Dnumber=E.Dno;

Unspecified WHERE clause and use of asterisk


Q9 and Q10. Select all emplyee SSn(q9) and all combinations of
Emplyee ssn and DEPARTMENT Dname(q10) in the database
Q9 SELECT Ssn
FROM EMPLOYEE;
Q10 SELECT Ssn,Dname
FROM EMPLOYEE,DEPARTMENT;
Q1C SELECT *
FROM EMPLOYEE
WHERE Dno=5;
Q1D SELECT *
FROM EMPLOYEE, DEPARTMENT
WHERE Dname=’Research’ AND
Dno=Dnumber;
Q10A SELECT *
FROM EMPLOYEE, DEPARTMENT;

Tables as sets in SQL


Q11. Retreive the salary of every employee(q11) and all distinct
salary values(q11a)
Q11 SELECT ALL Salary
FROM EMPLOYEE;
Q11A SELECT DISTINCT Salary
FROM EMPLOYEE;
Q4. Make a list of all project numbers for projects hat involve an
employee whose last name is ‘Smith’, either as a worker or as a
manager of the department that controls the project
Q4a (SELECT DISTINCT Pnumber
FROM PROJECT, DEPARTMENT, EMPLOYEE
WHERE Dnum=Dnumber AND Mgr_ssn=Ssn
AND Lname=’Smith’)
UNION
(SELECT DISTINCT Pnumber
FROM PROJECT, WORKS_ON, EMPLOYEE
WHERE Pnumber=Pno AND Essn=Ssn
AND Lname=’Smith’);
Substring pattern matching and arithmetic operators
Q12 Retreive all employees whose address is in houston , Texas
SELECT Fname,Lname
FROM EMPLOYEE
WHERE Address LIKE ‘%Houston,TX%’ ;
Q12A Find all employees who were born during 1950
SELECT Fname,Lname
FROM EMPLOYEE
WHERE Bdate LIKE ‘_ _ 5 _ _ _ _ _ _ _’ ;

You might also like