Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

PART 1

1. Create table employees (id int auto_increment, last_name varchar(50), first_name


varchar(50), department_id integer(5), position_id integer(50), PRIMARY KEY(id));
2. Create table positions (id int auto_increment, name varchar(50), PRIMARY KEY(id));
3. Create table departments (id int auto_increment, name varchar(50), PRIMARY
KEY(id));
4. Create table pay_details (id int auto_increment, employee_id integer(50), gross
integer(50), deductions integer(50), month varchar(20), year integer(20), PRIMARY
KEY(id));
5. INSERT INTO positions (name) VALUES (“Trainee”);
INSERT INTO positions (name) VALUES (“Rank and File”);
INSERT INTO positions (name) VALUES (“Supervisor”);
6. INSERT INTO departments(name) VALUES (“Sales”);
INSERT INTO departments(name) VALUES (“Human Resource”);
INSERT INTO departments(name) VALUES (“Administrative”);
INSERT INTO employees(last_name,first_name,department_id,position_id) VALUES
(“Lacson”,’Panfilo’,’1’,’1’);
INSERT INTO employees(last_name,first_name,department_id,position_id) VALUES
(“Marcos”,’Bongbong’,’3’,’2’);
INSERT INTO employees(last_name,first_name,department_id,position_id) VALUES
(“Robredo”,’Leni’,’2’,’2’);
INSERT INTO employees(last_name,first_name,department_id,position_id) VALUES
(“Moreno”,’Isko’,’1’,’1’);
INSERT INTO employees(last_name,first_name,department_id,position_id) VALUES
(“Duterte”,’Inday Sara’,’2’,’3’);
INSERT INTO employees(last_name,first_name,department_id,position_id) VALUES
(“Sotto”,’Tito’,’3’,’2’);
INSERT INTO employees(last_name,first_name,department_id,position_id) VALUES
(“Pangilinan”,’Kiko’,’3’,’1’);
INSERT INTO employees(last_name,first_name,department_id,position_id) VALUES
(“Ong”,’Willie’,’3’,’3’);

PART 2
1. SELECT employees.*,departments.* FROM employees INNER JOIN departments on
employees.department_id=departments.id;
2. SELECT employees.*,departments.*,positions.* FROM employees INNER JOIN
departments on employees.department_id=departments.id INNER JOIN positions ON
employees.position_id=positions.id;
3. SELECT employees.id,employees.last_name,employees.first_name,departments.name
AS department,positions.name AS position FROM employees INNER JOIN departments
on employees.department_id=departments.id INNER JOIN positions ON
employees.position_id=positions.id;
4. SELECT employees.id,employees.last_name,employees.first_name,departments.name
AS department,positions.name AS position FROM employees INNER JOIN departments
on employees.department_id=departments.id INNER JOIN positions ON
employees.position_id=positions.id ORDER BY employees.last_name ASC;
5. SELECT employees.id,employees.last_name,employees.first_name,departments.name
AS department,positions.name AS position FROM employees INNER JOIN departments
on employees.department_id=departments.id INNER JOIN positions ON
employees.position_id=positions.id WHERE employees.last_name LIKE 'm%';
6. SELECT employees.id,employees.last_name,employees.first_name,departments.name
AS department,positions.name AS position FROM employees INNER JOIN departments
on employees.department_id=departments.id INNER JOIN positions ON
employees.position_id=positions.id WHERE departments.name='Administrative';
7. SELECT employees.id,employees.last_name,employees.first_name,departments.name
AS department,positions.name AS position FROM employees INNER JOIN departments
on employees.department_id=departments.id INNER JOIN positions ON
employees.position_id=positions.id WHERE departments.name='Administrative' AND
positions.name='Rank and File';
8. SELECT employees.id,employees.last_name,employees.first_name,departments.name
AS department,positions.name AS position FROM employees INNER JOIN departments
on employees.department_id=departments.id INNER JOIN positions ON
employees.position_id=positions.id WHERE departments.name='Human Resource' OR
departments.name='Sales';
9. SELECT employees.id,employees.last_name,employees.first_name,departments.name
AS department,positions.name AS position FROM employees INNER JOIN departments
on employees.department_id=departments.id INNER JOIN positions ON
employees.position_id=positions.id WHERE (departments.name='Human Resource' OR
departments.name='Sales') AND positions.name='Supervisor';
10. SELECT employees.id,employees.last_name,employees.first_name,departments.name
AS department,positions.name AS position FROM employees INNER JOIN departments
on employees.department_id=departments.id INNER JOIN positions ON
employees.position_id=positions.id WHERE (departments.name='Human Resource' OR
departments.name='Sales') AND (positions.name='Supervisor' OR
positions.name='Trainee');

You might also like