-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode - queries
70 lines (55 loc) · 1.46 KB
/
Code - queries
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
-- Find all employees
SELECT *
FROM employee;
-- Find all clients
SELECT *
FROM clients;
-- Find all employees ordered by salary
SELECT *
from employee
ORDER BY salary ASC/DESC;
-- Find all employees ordered by sex then name
SELECT *
from employee
ORDER BY sex, name;
-- Find the first 5 employees in the table
SELECT *
from employee
LIMIT 5;
-- Find the first and last names of all employees
SELECT first_name, employee.last_name
FROM employee;
-- Find the forename and surnames names of all employees
SELECT first_name AS forename, employee.last_name AS surname
FROM employee;
-- Find out all the different genders
SELECT DISCINCT sex
FROM employee;
-- Find all male employees
SELECT *
FROM employee
WHERE sex = 'M';
-- Find all employees at branch 2
SELECT *
FROM employee
WHERE branch_id = 2;
-- Find all employee's id's and names who were born after 1969
SELECT emp_id, first_name, last_name
FROM employee
WHERE birth_day >= 1970-01-01;
-- Find all female employees at branch 2
SELECT *
FROM employee
WHERE branch_id = 2 AND sex = 'F';
-- Find all employees who are female & born after 1969 or who make over 80000
SELECT *
FROM employee
WHERE (birth_day >= '1970-01-01' AND sex = 'F') OR salary > 80000;
-- Find all employees born between 1970 and 1975
SELECT *
FROM employee
WHERE birth_day BETWEEN '1970-01-01' AND '1975-01-01';
-- Find all employees named Jim, Michael, Johnny or David
SELECT *
FROM employee
WHERE first_name IN ('Jim', 'Michael', 'Johnny', 'David');