DBMS: SQL for the Table Employee (E_ID, E_Name, Dept_Name, Salary, Address)

Consider the following relational schema.

Employee(E_ID, E_Name, Dept_Name, Salary, Address)

 

Now write down the SQL for the following:

  1. Display E_Name who is taking maximum salary.
  2. Display all Dept_Name where number of Employees are less than 10.
  3. Display E_Name of employee whose address is either Mechi, Nepalgunj or Pokhara.
  4. Display E_ID and E_Name of employees whose name starts with “S” and Ends with “M”.
  5. Increase the salary of employees by 50% whose salary is less than 10000.

i. Display E_Name who is taking maximum salary.


SELECT E_Name
FROM   Employee
WHERE  Salary = (SELECT MAX(Salary) FROM   Employee);

---- OR ----

SELECT E_Name FROM   Employee
ORDER  BY Salary DESC
LIMIT  1;

 

ii. Display all Dept_Name where number of Employees are less than 10.


SELECT Dept_Name, COUNT(E_ID)
FROM   Employee
GROUP  BY Dept_Name
HAVING COUNT(E_ID) < 10;

 

iii. Display E_Name of employee whose address is either Mechi, Nepalgunj or Pokhara.


SELECT E_Name
FROM   Employee
WHERE  Address IN ( "Mechi", "Nepalgunj", "Pokhara" );

---- OR ----

SELECT E_Name
FROM   Employee
WHERE  Address = "Mechi" OR Address =  "Nepalgunj" 
OR Address =  "Pokhara" ;

 

iv. Display E_ID and E_Name of employees whose name starts with “S” and ends with “M”.


SELECT E_ID, E_Name
FROM   Employee
WHERE  E_Name LIKE "S%M";

 

v. Increase the salary of employees by 50% whose salary is less than 10000.


UPDATE Employee
SET    Salary = Salary * 1.5
WHERE  Salary < 10000;