-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhr_query_practice.sql
More file actions
58 lines (38 loc) · 1.02 KB
/
hr_query_practice.sql
File metadata and controls
58 lines (38 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
create database hr;
use hr;
/**create**/
create table departments(
department_id int(11) auto_increment primary key,
dept_name varchar(100)
);
create table employee(
id int auto_increment primary key,
first_name varchar(50) not null,
last_name varchar(50) not null,
department_id int(11) not null,
foreign key(department_id)
references departments(department_id)
);
/**insert**/
insert into departments(dept_name)
values('sales'),
('marketing'),
('Finance'),
('Accounting'),
('Warehouse'),
('Production');
insert into employee(first_name,last_name,department_id)
values ('John','Doe',1),
('Buhs','liya',2),
('David','Mallan',3);
select department_id,dept_name from departments;
select id,first_name,last_name,department_id from employee;
create view v_employee_info as select
id,first_name,last_name,dept_name
from
employee
inner join
departments using(department_id) ;
select * from departments;
select * from employee;
select * from v_employee_info;