SQL SERVER QUERY INTERVIEW QUESTIONS - ANSWERS WITH EXAMPLE FOR FRESHER : SET-1 SOLUTION

SQL SERVER/Oracle/MySQL INTERVIEW QUERY SET : 1 WITH ANSWERS/SOLUTION

Here I come with more than 100 SQL Server queries for Database/.NET/SQL Server developers, Soon you will get more than 100 SQL query set in pdf/ebook format. So keep visiting this page.
This is for both fresher and experienced developers which would be helpful for Interview preparation.
First try to answer these queries and put comment. After that see the answers of each query in solution set.
Download as PDF

Tables:-






MS SQL/Oracle/MySQL INTERVIEW QUERY FOR FRESHER SET : 1 SOLUTION


1. Write a query to get all employee detail from "EmployeeDetail" table 
ANS:
MS SQL Server: SELECT * FROM EmployeeDetail

Oracle:                SELECT * FROM EmployeeDetail

MySQL:              SELECT * FROM EmployeeDetail


2. Write a query to get only "FirstName" column from "EmployeeDetail" table 
ANS:
MS SQL Server: SELECT FirstName FROM EmployeeDetail

Oracle:                SELECT FirstName FROM EmployeeDetail

MySQL:              SELECT FirstName FROM EmployeeDetail
 



3. Write a query to get FirstName in upper case as "First Name". 
ANS:
MS SQL Server: SELECT UPPER(FirstName) AS [First Name]  FROM EmployeeDetail
Oracle:                SELECT UPPER(FirstName) AS [First Name]  FROM EmployeeDetail
MySQL:             SELECT UPPER(FirstName) AS [First Name]  FROM EmployeeDetail



4. Write a query to get FirstName in lower case as "First Name". 
ANS:
MS SQL Server: SELECT LOWER(FirstName) AS [First Name]  FROM EmployeeDetail
Oracle:                SELECT LOWER(FirstName) AS [First Name]  FROM EmployeeDetail
MySQL:             SELECT LOWER(FirstName) AS [First Name]  FROM EmployeeDetail




5. Write a query for combine FirstName and LastName and display it as "Name" (also include white space between first name & last name) 
ANS:
MS SQL Server: SELECT FirstName +' '+ LastName AS [Name]  FROM EmployeeDetail
Oracle:                  SELECT FirstName ||' '|| LastName AS [Name]  FROM EmployeeDetail
MySQL:               SELECT CONCAT(FirstName ,' ', LastName) AS [Name]  FROM EmployeeDetail





6. Select employee detail whose name is "Vikas" 
ANS:
MS SQL Server: SELECT * FROM EmployeeDetail WHERE FirstName = 'Vikas'

Oracle:                SELECT * FROM EmployeeDetail WHERE FirstName = 'Vikas'

MySQL:             SELECT * FROM EmployeeDetail WHERE FirstName = 'Vikas'






7. Get all employee detail from EmployeeDetail table whose "FirstName" start with latter 'a'. 
ANS:
MS SQL Server: SELECT * FROM EmployeeDetail WHERE FirstName like 'a%'

Oracle:                SELECT * FROM EmployeeDetail WHERE FirstName like 'a%'

MySQL:              SELECT * FROM EmployeeDetail WHERE FirstName like 'a%'







8. Get all employee details from EmployeeDetail table whose "FirstName" contains 'k' 
ANS:
MS SQL Server: SELECT * FROM EmployeeDetail WHERE FirstName like '%k%'

Oracle:                SELECT * FROM EmployeeDetail WHERE FirstName like '%k%'

MySQL:             SELECT * FROM EmployeeDetail WHERE FirstName like '%k%'




9. Get all employee details from EmployeeDetail table whose "FirstName" end with 'h' 
ANS:
MS SQL Server: SELECT * FROM EmployeeDetail WHERE FirstName like '%h'

Oracle:                SELECT * FROM EmployeeDetail WHERE FirstName like '%h'

MySQL:             SELECT * FROM EmployeeDetail WHERE FirstName like '%h'





10. Get all employee detail from EmployeeDetail table whose "FirstName" start with any single character between 'a-p' 
ANS:
MS SQL Server: SELECT * FROM EmployeeDetail WHERE FirstName like '[a-p]%'

Oracle:                SELECT * FROM EmployeeDetail WHERE FirstName like '[a-p]%'

MySQL:             SELECT * FROM EmployeeDetail WHERE FirstName like '[a-p]%'


Click on the following link for NEXT SET OF QUESTIONS:
CLICK HERE FOR NEST SET (MORE THAN 100 QUERIES)

Comments

  1. very useful for me

    ReplyDelete
  2. Will all above queries work for normal D.Bases too? I saw these are server query interviews.

    ReplyDelete
  3. Great Article it will help for Freshers as well as experienced professionals

    ReplyDelete
  4. Great Article it will help for Freshers as well as experienced professionals

    ReplyDelete
  5. Thanks all of above commenters for your kind comments

    ReplyDelete
  6. Thanks all of above commenters for your kind comments

    ReplyDelete
  7. Thanks a lot Vikas for preparing this Q&A series, really very much helpful.

    ReplyDelete
  8. Shouldn't you use lower(Firstname) like 'a%' in question 7?

    ReplyDelete
    Replies
    1. No, bcoz it does not matter as sql query is not case sensitive.

      Delete
    2. SQL is case sensitive

      Delete
  9. Dear Vikas really its very useful details shared by this blog .May you send me pdf of "SQL INTERVIEW QUESTION ANSWER" at vipinkamboj13@gmail.com

    ReplyDelete
  10. Thank You sir.. Very UseFul

    ReplyDelete
  11. dear anyone can provide a pdf of that type query on deepak.technologist@gmail.com

    ReplyDelete
  12. sanketbeloshe2@gmail.com please give me pdf sir 1 to 6 sql basic questions answers

    ReplyDelete
  13. This is an useful resource. Thank You :)

    ReplyDelete
  14. how to get this database schema

    ReplyDelete
  15. Really very helpful for freshers
    Thanks

    ReplyDelete
  16. Good explaination for the fresher, Thanks!!

    ReplyDelete
  17. hi,how to insert date and time

    ReplyDelete

Archive

Contact Form

Send