0% found this document useful (0 votes)
499 views6 pages

Sample Table Employee Employee - Id First - Name Last - Name Salary Joining - Date Department

The document provides sample SQL queries and tables to practice basic SQL skills. It includes sample Employee, Bonus, and Title tables with seeded data. It then provides 20 questions asking to write SQL queries to retrieve or filter data from the Employee table based on conditions on columns like name, department, salary, and date.

Uploaded by

Sanket Dhepe
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)
499 views6 pages

Sample Table Employee Employee - Id First - Name Last - Name Salary Joining - Date Department

The document provides sample SQL queries and tables to practice basic SQL skills. It includes sample Employee, Bonus, and Title tables with seeded data. It then provides 20 questions asking to write SQL queries to retrieve or filter data from the Employee table based on conditions on columns like name, department, salary, and date.

Uploaded by

Sanket Dhepe
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/ 6

Prepare Sample Data to Practice SQL Skill.

===========================

Sample Table → Employee

EMPLOYEE_ID FIRST_NAME LAST_NAME


SALARY JOINING_DATE DEPARTMENT

001 Monika Arora 100000 2014–02–20 09:00:00 HR


002 Niharika Verma 80000 2014–06–11 09:00:00
Admin 003 Vishal Singhal 300000 2014–02–20
09:00:00 HR 004 Amitabh Singh 500000 2014–02–20
09:00:00 Admin 005 Vivek Bhati 500000 2014–06–11
09:00:00 Admin 006 Vipul Diwan 200000 2014–06–11
09:00:00 Account
007 Satish Kumar 75000 2014–01–20 09:00:00 Account
008 Geetika Chauhan 90000 2014–04–11 09:00:00
Admin Sample Table → Bonus
EMPLOYEE_REF_ID BONUS_DATE
BONUS_AMOUNT 1 2016–02–20 00:00:00 5000
2 2016–06–11 00:00:00 3000
3 2016–02–20 00:00:00 4000
1 2016–02–20 00:00:00 4500
2 2016–06–11 00:00:00 3500
Sample Table →Title
EMPLOYEE_REF_ID EMPLOYEE_TITLE
AFFECTED_FROM
1 Manager 2016–02–20 00:00:00
2 Executive 2016–06–11 00:00:00
8 Executive 2016–06–11 00:00:00
5 Manager 2016–06–11 00:00:00
4 Asst. Manager 2016–06–11 00:00:00
7 Executive 2016–06–11 00:00:00
6 Lead 2016–06–11 00:00:00
3 Lead 2016–06–11 00:00:00
To prepare the sample data, you can run the following
queries in your database query executor or on the SQL
command line. I’ve tested them with MySQL Server
5.7.

SQL Script to Seed Sample Data.


====================
CREATE DATABASE ORG;
SHOW DATABASES;
USE ORG;

CREATE TABLE Employee(


EMPLOYEE_ID INT NOT NULL PRIMARY
KEY AUTO_INCREMENT,
FIRST_NAME CHAR(25),
LAST_NAME CHAR(25),
SALARY INT(15),
JOINING_DATE DATETIME,
DEPARTMENT CHAR(25)
);
INSERT INTO Employee
(Employee_ID, FIRST_NAME, LAST_NAME,
SALARY, JOINING_DATE, DEPARTMENT) VALUES
(001, ‘Monika’, ‘Arora’, 100000, ‘14–02–20
09.00.00’, ‘HR’),
(002, ‘Niharika’, ‘Verma’, 80000, ‘14–06–11
09.00.00’, ‘Admin’),
(003, ‘Vishal’, ‘Singhal’, 300000, ‘14–02–20
09.00.00’, ‘HR’),
(004, ‘Amitabh’, ‘Singh’, 500000, ‘14–02–20
09.00.00’, ‘Admin’),
(005, ‘Vivek’, ‘Bhati’, 500000, ‘14–06–11
09.00.00’, ‘Admin’),
(006, ‘Vipul’, ‘Diwan’, 200000, ‘14–06–11
09.00.00’, ‘Account’),
(007, ‘Satish’, ‘Kumar’, 75000, ‘14–01–20
09.00.00’, ‘Account’),
(008, ‘Geetika’, ‘Chauhan’, 90000, ‘14–04–11
09.00.00’, ‘Admin’);

CREATE TABLE Bonus (


Employee_REF_ID INT,
BONUS_AMOUNT INT(10),
BONUS_DATE DATETIME,
FOREIGN KEY (Employee_REF_ID)
REFERENCES Employee(Employee_ID)
ON DELETE CASCADE
);

INSERT INTO Bonus


(Employee_REF_ID, BONUS_AMOUNT,
BONUS_DATE) VALUES
(001, 5000, ‘16–02–20’),
(002, 3000, ‘16–06–11’),
(003, 4000, ‘16–02–20’),
(001, 4500, ‘16–02–20’),
(002, 3500, ‘16–06–11’);
CREATE TABLE Title (
Employee_REF_ID INT,
Employee_TITLE CHAR(25),
AFFECTED_FROM DATETIME,
FOREIGN KEY (Employee_REF_ID)
REFERENCES Employee(Employee_ID)
ON DELETE CASCADE
);

INSERT INTO Title


(Employee_REF_ID, Employee_TITLE,
AFFECTED_FROM) VALUES
(001, ‘Manager’, ‘2016–02–20 00:00:00’),
(002, ‘Executive’, ‘2016–06–11 00:00:00’),
(008, ‘Executive’, ‘2016–06–11 00:00:00’),
(005, ‘Manager’, ‘2016–06–11 00:00:00’),
(004, ‘Asst. Manager’, ‘2016–06–11
00:00:00’), (007, ‘Executive’, ‘2016–06–11
00:00:00’),
(006, ‘Lead’, ‘2016–06–11 00:00:00’),
(003, ‘Lead’, ‘2016–06–11 00:00:00’);

Once above SQL would run, you’ll see a result similar


to the one attached below.
Q-1. Write an SQL query to fetch “FIRST_NAME”
from Employee table using the alias name as
<EMPLOYEE_NAME>.

Q-2. Write an SQL query to fetch “FIRST_NAME” from


EMPLOYEE table in upper case.

Q-3. Write an SQL query to fetch unique values


of DEPARTMENT from EMPLOYEE table.
Ans.

Q-4. Write an SQL query to print the first three


characters of FIRST_NAME from EMPLOYEE table.

Q-5. Write an SQL query to find the position of the


alphabet (‘a’) in the first name column ‘Amitabh’
from EMPLOYEE table.

Q-6. Write an SQL query to print the FIRST_NAME


from EMPLOYEE table after removing white spaces
from the
right side.

Q-7. Write an SQL query to print the DEPARTMENT


from EMPLOYEE table after removing white spaces
from the left side.

Q-8. Write an SQL query that fetches the unique values


of DEPARTMENT from EMPLOYEE table and prints its
length.

Q-9. Write an SQL query to print the FIRST_NAME


from EMPLOYEE table after replacing ‘a’ with ‘A’. Ans.
Q-10. Write an SQL query to print the FIRST_NAME and
LAST_NAME from EMPLOYEE table into a single
column
COMPLETE_NAME. A space char should separate
them.

Q-11. Write an SQL query to print all EMPLOYEE


details from the EMPLOYEE table order by
FIRST_NAME Ascending.

Q-12. Write an SQL query to print all EMPLOYEE


details from the EMPLOYEE table order by
FIRST_NAME Ascending and DEPARTMENT
Descending.

Q-13. Write an SQL query to print details for


EMPLOYEEs with the first name as “Vipul” and “Satish”
from EMPLOYEE table.

Q-14. Write an SQL query to print details of


EMPLOYEEs excluding first names, “Vipul” and
“Satish” from EMPLOYEE table.

Q-15. Write an SQL query to print details of


EMPLOYEEs with DEPARTMENT name as “Admin”.

Q-16. Write an SQL query to print details of


the EMPLOYEEs whose FIRST_NAME
contains ‘a’.

Q-17. Write an SQL query to print details of the


EMPLOYEEs whose FIRST_NAME ends with
‘a’.

Q-18. Write an SQL query to print details of the


EMPLOYEEs whose FIRST_NAME ends with ‘h’
and contains six alphabets.
Q-19. Write an SQL query to print details of the
EMPLOYEEs whose SALARY lies between 100000
and 500000.

Q-20. Write an SQL query to print details of


the EMPLOYEEs who have joined in Feb’2014.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy