0% found this document useful (0 votes)
9 views1 page

Lab 1 Database

The document contains a series of SQL queries for retrieving and manipulating data from an 'employees' table. It includes queries for displaying names with aliases, getting unique department IDs, ordering employee details, calculating total salaries, and retrieving salary statistics. Additionally, it covers queries for counting jobs, converting names to uppercase, and selecting specific records from the table.

Uploaded by

Basit Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Lab 1 Database

The document contains a series of SQL queries for retrieving and manipulating data from an 'employees' table. It includes queries for displaying names with aliases, getting unique department IDs, ordering employee details, calculating total salaries, and retrieving salary statistics. Additionally, it covers queries for counting jobs, converting names to uppercase, and selecting specific records from the table.

Uploaded by

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

1.

Write a query to display the names (first_name, last_name) using alias name
“First
Name", "Last Name".
QUERY 1:
mysql> select first_name AS 'First name', last_name AS 'Last name' from employees;
2. Write a query to get unique department ID from employee table.
QUERY 2:
select distinct department_id from employees;
3. Write a query to get all employee details from the employee table order by first
name,
descending.
QUERY 3:
select * from employees order by first_name desc;
4. Write a query to get the employee ID, names (first_name, last_name), salary in
ascending order of salary.
QUERY 4:
select employee_id,first_name,last_name,salary from employees order by salary asc;
5. Write a query to get the total salaries payable to employees.
QUERY 5:
select sum(salary) as "total salaries" from employees;
6. Write a query to get the maximum and minimum salary from employees table
QUERY 6:
select max(salary) as "maximum salary", min(salary) as "minimum salary" from
employees;
7. Write a query to get the average salary and number of employees in the employees
table.
QUERY 7:
select avg(salary) as "average salary", count(*) as "number of employees" from
employees;
8. Write a query to get the number of jobs available in the employees table.
QUERY 8:
select count(distinct job_id) as "number of jobs" from employees;
9. Write a query get all first name from employees table in upper case.
QUERY 9:
select upper(first_name) as "first name" from employees;
10. Write a query to select first 10 records from a table.
QUERY 10:
select * from employees limit 10;
11. Write a query to select 3rd & 4th record of employees table.
QUERY 11:
select * from employees limit 3,4;
12. Write a query to select 2nd last record of employees table.
QUERY 12:
select * from employees order by employee_id desc limit 1 offset 1;

You might also like