0% found this document useful (0 votes)
19 views

Assignment of Subqueries2

The document discusses various SQL queries using subqueries including: 1) Selecting customers where id is in a subquery selecting ids of customers with salary over 49000. 2) Updating customer salaries to be doubled where age is in a subquery selecting quantities over 17 from orders. 3) Selecting employee names where salary equals the maximum salary from a subquery. 4) Selecting employees where salary does not equal the minimum salary from a subquery. 5) Selecting departments and counts of employees grouped by department.

Uploaded by

Knowledge point
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Assignment of Subqueries2

The document discusses various SQL queries using subqueries including: 1) Selecting customers where id is in a subquery selecting ids of customers with salary over 49000. 2) Updating customer salaries to be doubled where age is in a subquery selecting quantities over 17 from orders. 3) Selecting employee names where salary equals the maximum salary from a subquery. 4) Selecting employees where salary does not equal the minimum salary from a subquery. 5) Selecting departments and counts of employees grouped by department.

Uploaded by

Knowledge point
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment of subqueries

 Select * from customers where id in(select id from customers where salary >49000);

 update customers set SALARY= SALARY*2

where age in (select qty from orders where qty>=17)

 select e_name from employee where salary= (select max(salary) from employee);

 select * from employee where salary <>(SELECT min(salary) from employee);

 select dept,count(*) from employee group by dept;

 select * from employee where

dept in (select dept from employee group by dept having count(*)<2);

 select e_name from employee where salary in (select max(salary) from employee group by
dept)
ASSIGNMENT PROCEDURE PARAMETER
DELIMITER $$ CREATE PROCEDURE detail() BEGIN

SELECT fname,lname,MAX(salary) FROM staff ; END$$;

CALL detail();

DELIMITER $$ CREATE PROCEDURE kamra() BEGIN

DECLARE a INT DEFAULT 15; DECLARE b,c INT; SET b=5;

SET c=a+b; SELECT a,b,c; END$$;

CALL karma;

DELIMITER $$ CREATE PROCEDURE MY_PROC (IN VAR INT)

BEGIN SELECT * FROM STAFF LIMIT VAR; NEND$$

CALL MY_PROC(4);
SELECT POSITION,STREET FROM STAFF S

INNER JOIN branch R ON S.BRANCHNO=R.BRANCHNO;

You might also like