Tuesday, 10 March 2015

String Related SQL Query Interview Questions

1. Write a SQL Query to get the details from employee table whose "FirstName" not start with any single character between 'a-p'.

Ans: Select * from employee where FirstName like '[^a-p]%'.

2. Write a SQL Query to get the details from employee table whose "Gender" end  with 'le' and contain 4 letters.

Ans: Select * from employee where Gender like '_le'. (there are two "__")

3. Write a SQL Query to get the details from employee table whose "FirstName start with 'A' and contain 5 letters.

Ans: Select * from employee where FirstName like 'A____'. (there are four "____")

4. Write a SQL Query to get the details from employee table whose "FirstName containing '%'. Ex: 'Vik%as'

Ans: Select * from employee where FirstName like '%[%]%'.

Note : According to table if FirstName column contains % then it will fetch the details otherwise it won't.

5. Write a SQL Query to get unique department from employee table.

Ans: Select distinct (department) from employee.

6. Write a SQL Query to get highest salary from employee table.

Ans: Select max (salary) from employee.

7. Write a SQL Query to get lowest salary from employee table.

Ans: Select min (salary) from employee.

No comments:

Post a Comment