SALARY : SQL INTERVIEW QUERIES EXAMPLES FOR FRESHER AND EXPRINCED SET-4

Hey this is 4th set of SQL Interview Queries series, this set containing IN,NOT IN and Salary related SQL queries which is asked most frequently in every sql server interview, so this set containing most important salary related interview queries with example.

So lets start SQL Quiz. SET-4 (31-41)
Related Tables:-



31. Select only one/top 1 record from "EmployeeDetail" table.
Ans: SELECT TOP 1 * FROM [EmployeeDetail]


32. Select all employee detail with First name "Vikas","Ashish", and "Nikhil".
Ans: SELECT * FROM [EmployeeDetail] WHERE FirstName IN('Vikas','Ashish','Nikhil')


33. Select all employee detail with First name not in "Vikas","Ashish", and "Nikhil".
Ans: SELECT * FROM [EmployeeDetail] WHERE FirstName NOT IN('Vikas','Ashish','Nikhil')


34. Select first name from "EmployeeDetail" table after removing white spaces from right side
Ans: SELECT RTRIM(FirstName) AS [FirstName] FROM [EmployeeDetail]


35. Select first name from "EmployeeDetail" table after removing white spaces from left side
Ans: SELECT LTRIM(FirstName) AS [FirstName] FROM [EmployeeDetail]


36. Display first name and Gender as M/F.(if male then M, if Female then F)
Ans: SELECT FirstName, CASE  WHEN Gender = 'Male' THEN 'M'
WHEN Gender = 'Female' THEN 'F' END AS [Gender]
FROM [EmployeeDetail]


37. Select first name from "EmployeeDetail" table prifixed with "Hello "
Ans: SELECT 'Hello ' + FirstName FROM [EmployeeDetail]


38. Get employee details from "EmployeeDetail" table whose Salary greater than 600000
Ans: SELECT * FROM [EmployeeDetail] WHERE Salary > 600000


39. Get employee details from "EmployeeDetail" table whose Salary less than 700000
Ans: SELECT * FROM [EmployeeDetail] WHERE Salary < 700000


40. Get employee details from "EmployeeDetail" table whose Salary between 500000 than 600000
Ans: SELECT * FROM [EmployeeDetail] WHERE Salary BETWEEN 500000 AND 600000


41. Select second highest salary from "EmployeeDetail" table.
Ans: SELECT TOP 1 Salary FROM
(SELECT TOP 2 Salary FROM [EmployeeDetail] ORDER BY Salary DESC) T ORDER BY Salary ASC


Click here for next set(MORE THAN 100 QUERIES)

Comments

  1. very helpful...sir please send me pdf on.....mbhosale109@gmail.com

    ReplyDelete
  2. I want some SQL queries related to fresher and experience interview question.
    This is m mail I'd: sadana.5b2@gmail.com.
    Plz send me sir...

    ReplyDelete
  3. Please mail me the pdf file at jmehul64.mj@gmail.com

    ReplyDelete
  4. the answer for question 41 is wrong.
    It should be

    SELECT TOP 1* from (SELECT TOP 2* FROM EmployeeDetails order by SALARY ASC) T
    order by SALARY DESC

    ReplyDelete
    Replies
    1. that whole query is creates another table that table named as 'T'

      Delete
  5. 41.Ans also be like

    select MAX(Salary) from EmployeeDetail where Salary <(Select MAX(Salary) from EmployeeDetail)

    ReplyDelete
  6. sir very helpful article can you please share me these Q and A @shabashi2482@gmail.com
    thanks in advance

    ReplyDelete

Archive

Contact Form

Send