0% found this document useful (0 votes)
3 views

DBMS Lab 3

The document contains a series of SQL queries designed to manipulate and retrieve data from an HR database. It includes instructions for generating new employee names, modifying job titles, displaying hire dates, formatting dates, and extracting specific information from employee and location records. Each query is preceded by commands to show databases and tables, ensuring the correct context for data retrieval.
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)
3 views

DBMS Lab 3

The document contains a series of SQL queries designed to manipulate and retrieve data from an HR database. It includes instructions for generating new employee names, modifying job titles, displaying hire dates, formatting dates, and extracting specific information from employee and location records. Each query is preceded by commands to show databases and tables, ensuring the correct context for data retrieval.
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/ 19

1.

Write a query to generate new names of the employees by


combining the first 3 characters of the First_Name and last
3 characters of the job.
show databases;
use hr;

show tables;
select * from employees;
select first_name, last_name, concat (left(first_name, 3), right(last_name, 3)) as
"Concat"from employees;
2. Generate new jobs of the employees by changing letter E
with A in the existing jobs.
show databases;
use hr;

show tables;
select * from employees;
select job_id, replace(job_id,'E','A') as "New jobs" from employees;
3. Write a query to Display Names, hire date years in the
department.
show databases;
use hr;

show tables;
select * from employees;
select first_name, last_name, year(hire_date) as "Year" from employees;
4. Write a query to display names, hire date of all the
employees who were hired before July 30, 1987. Keeping
this in mind that hire dates should be displayed in the
format “MONTH DATE, YEAR”. Also date in the where
clause should be in the format “MONTH DATE, YEAR”.
show databases;
use hr;

show tables;
select * from employees;
select date_format(hire_date, '%m %d %y') as "format_date" from employees where
hire_date < '1987-07-30';

5. Write a query to display the last day of the current month


& three months before the current month
show databases;
use hr;

show tables;
select * from employees;
select datediff('2025-03-07', current_date()) as "The last day",
date_sub(current_date(), interval 3 month) as "date diff";
6. Write a query to get the day of the current year.
show databases;
use hr;

show tables;
select * from employees;
select datediff(current_time(), '2025-01-01');
7. Write a query to get the day of the current year.
show databases;
use hr;

show tables;
select * from employees;
SELECT DATE_FORMAT(current_DATE(), '%M, %d, %Y') as "New format" ;
8. Write a query to get the current date in Thursday
September 2014 format.
show databases;
use hr;

show tables;
select * from employees;
SELECT DATE_FORMAT(current_DATE(), '%M, %W, %Y') as "New format" ;
9. Write a query to get the first name and hire date from
employees table where hire date between '1987-06-01'
and '1987-07-30'.
show databases;
use hr;

show tables;
select * from employees;
SELECT first_name, hire_date from employees where hire_date between '1987-06-01'
and '1987-07-30' ;
10. Write a query to display the current date in the
05/09/2014 format
show databases;
use hr;

show tables;
select * from employees;
SELECT date_format(current_date, '%d / %m / %Y') as "New Format";
11. Write a query to get the firstname, lastname who
joined in the month of June
show databases;
use hr;

show tables;
select * from employees;
SELECT first_name, last_name, hire_date from employees where hire_date like
'_____06___';
12. Write a query to append '@iba-suk.edu.pk' to email
field
show databases;
use hr;

show tables;
select * from employees;
SELECT concat(email,'@iba-suk.edu.pk') as "Complete Email" from employees;
13. Write a query to get the employee id, first name and
hire month using MID().
show databases;
use hr;

show tables;
select * from employees;
SELECT mid(last_name,1,length(last_name)) as "Last name",
mid(employee_id,1,length(employee_id)) as "employee id",
mid(hire_date,1,length(hire_date)) as "hire date" from employees;
14. Write a query to extract the last 4 character of phone
numbers.
show databases;
use hr;

show tables;
select * from employees;
SELECT right(phone_number,4) from employees;
15. Write a query to get the last word of the street
address(from locations able)
show databases;
use hr;

show tables;
select * from locations;
SELECT right(street_address,4) from locations;
16. Write a query to get the locations that have minimum
street length.(locations tbl)
show databases;
use hr;

show tables;
select * from locations;
SELECT min(length(street_address)) as "Minimum length" from locations;
17. Write a query to display the first word from those job
titles which contains more than one word.
show databases;
use hr;

show tables;
select * from jobs;
SELECT substr(job_title, 1 ,Instr(job_title, ' ')) as "first_name" from jobs where
instr(job_title, ' ') > 0;
18. Write a query to display the length of first name for
employees where last name contain character 'c' after 2nd
position
show databases;
use hr;

show tables;
select * from employees;
SELECT last_name, length(last_name) as "Trimmed" from employees where last_name
like '__c%';

You might also like