-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIMPORTANT queries.sql
More file actions
73 lines (56 loc) · 1.41 KB
/
Copy pathIMPORTANT queries.sql
File metadata and controls
73 lines (56 loc) · 1.41 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
USE xyz;
SELECT * FROM employee;
SELECT *
FROM employee
WHERE salary =(SELECT MAX(salary) FROM employee);
-- Display the the of the employee who has the 2nd largest salary
SELECT name
FROM employee
WHERE salary IN(
SELECT MAX(salary)
FROM employee
WHERE salary <>(SELECT MAX(salary) FROM employee));
SELECT department,COUNT(*) AS no_of_employees
FROM employee
GROUP BY department;
SELECT department,COUNT(*) AS no_of_employees
FROM employee
GROUP BY department
HAVING COUNT(*)<2;
-- Display the name of employee where only one employee is there is department
SELECT name
FROM employee
WHERE department IN(
SELECT department
FROM employee
GROUP BY department
HAVING COUNT(*)<2
);
-- Display the name of the employee who has taking highest salary in respective department
SELECT name,department,salary
FROM employee e
WHERE (salary) IN (
SELECT MAX(salary)
FROM employee
WHERE department=e.department
);
SELECT * FROM employee
WHERE city IN ('BANGLORE','MORADABAD','SAHARANPUR');
SELECT * FROM employee
WHERE city NOT IN ('BANGLORE');
SELECT MAX(salary)
FROM employee
GROUP BY department;
SELECT * FROM customer;
SELECT * FROM c_order;
-- EXISTS/NOTEXISTS is used in corelated sub query
SELECT name
FROM customer c
WHERE EXISTS (SELECT 1
FROM c_order o
WHERE o.id=c.id );
SELECT name
FROM Customer c
WHERE NOT EXISTS (SELECT 1
FROM c_order o
WHERE o.id=c.id );