0% found this document useful (0 votes)
26 views6 pages

EXP6

Uploaded by

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

EXP6

Uploaded by

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

Expo

AimiNeste Cueald uimG UNNOT INJEme,an

The N Cpeaa bo
Va lwes claset
ebrm brue f the value nmathesamy yalue

2) NOTIN
The NoTLN Opexa bov it Fec bopey a Jut
of vawes for Cemmpaason inuHERe clate
ebuand s u e f bhe vawe cees ne mat
Cny vawe in he lsl

3)JoME /ANY
The
Jubasay Tubquey lreburas tue 4the ompas
bue hakleast one valwe n b¥e beé

4), ExitI
bo bed a tuealhe
hcieny cnacthease pDefomeel
eu beCom
sebieval
taslks thin lu
queies emmbedbmg caba eenmplex byqueaies
mamipulabe
bada
mad filbe buens fullPowen aConcite
amc
Clasect ebh Exubs In Like bong Opeu
lueng dQt, ineuees Ceonclusioni
ested
bement. Jta deL ingle af
Jcepe
ci
hin sefered beCen bhat feb eulb nomec
bu yuu alleug xpreaien bablu
Ce ag
known clso CLAutg llTH Th
CLAwe wTH 6)
Jubguesy itbne
lcbhes
a
beok bo
EXII 5),NOT
312
exp6
CREATE TABLE DEP (
department_id INT PRIMARY KEY,
department_name VARCHAR(50),
location_id INT
);
INSERT INTO DEP (department_id, department_name, location_id)
VALUES
(1, 'HR', 1700),
(2, 'Finance', 1800),
(3, 'IT', 1700);

1> USING IN
SELECT *
FROM DEP
WHERE location_id IN (1700, 1800);

2>USING NOT IN
-- Select departments not located in location_id 1700
SELECT *
FROM departments
WHERE location_id NOT IN (1700, 1800);

3>USING ANY
SELECT *
FROM DEP
WHERE department_id IN (
SELECT department_id
FROM employees
GROUP BY department_id
HAVING COUNT(*) > 1
);

4>USING IN
-- Select departments with at least one employee earning more than $60000
SELECT *
FROM department
WHERE department_id IN (
SELECT department_id
FROM employees
WHERE salary > 60000
);

5> USING EXIST


-- Select departments with at least one employee
SELECT *
FROM department d
WHERE EXISTS (
SELECT 1
FROM employees e
WHERE e.department_id = d.department_id
);
6> USING NOT EXIST
-- Select departments with no employees
SELECT *
FROM departments d
WHERE NOT EXISTS (
SELECT 1
FROM employees e
WHERE e.department_id = d.department_id
);

8> USING WITH

-- Select departments along with the total number of employees


WITH department_employee_count AS (
SELECT d.department_id, d.department_name, COUNT(e.employee_id) AS num_employees
FROM departments d
LEFT JOIN employees e ON d.department_id = e.department_id
GROUP BY d.department_id, d.department_name
)
SELECT *
FROM department_employee_count;

You might also like