Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
226 views

SQL Practice Set 1 & 2

Uploaded by

02shreyansh03.09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
226 views

SQL Practice Set 1 & 2

Uploaded by

02shreyansh03.09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Here our step by step SQL Server Interview Questions/ TSQL Queries asked during

interview.

Set-1: Sql Server Basic Interview Query


Tables:-

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]%'
Set-2: Sql Server Basic Interview Query
Related Tables:-

Questions Answers

11). Get all employee detail from EmployeeDetail table whose "FirstName" not start
with any single character between 'a-p'
Ans: SELECT * FROM [EmployeeDetail] WHERE FirstName like '[^a-p]%'

12). Get all employee detail from EmployeeDetail table whose "Gender" end with 'le'
and contain 4 letters. The Underscore(_) Wildcard Character represents any single
character.
Ans: SELECT * FROM [EmployeeDetail] WHERE Gender like ' le' --there are two "_"

13). Get all employee detail from EmployeeDetail table whose "FirstName" start with
'A' and contain 5 letters.
Ans: SELECT * FROM [EmployeeDetail] WHERE FirstName like 'A ' --there are four "_"

14). Get all employee detail from EmployeeDetail table whose "FirstName"
containing '%'. ex:-"Vik%as".
Ans: SELECT * FROM [EmployeeDetail] WHERE FirstName like '%[%]%'
--According to our table it would return 0 rows, because no name containg '%'

15). Get all unique "Department" from EmployeeDetail table.


Ans: SELECT DISTINCT(Department) FROM [EmployeeDetail]

16). Get the highest "Salary" from EmployeeDetail table.


Ans: SELECT MAX(Salary) FROM [EmployeeDetail]

17). Get the lowest "Salary" from EmployeeDetail table.


Ans: SELECT MIN(Salary) FROM [EmployeeDetail]

***SQL SERVER DATE RELATED INTERVIEW QUERY***

18). Show "JoiningDate" in "dd mmm yyyy" format, ex- "15 Feb 2013"
Ans: SELECT CONVERT(VARCHAR(20),JoiningDate,106) FROM [EmployeeDetail]

19). Show "JoiningDate" in "yyyy/mm/dd" format, ex- "2013/02/15"


Ans: SELECT CONVERT(VARCHAR(20),JoiningDate,111) FROM [EmployeeDetail]

20). Show only time part of the "JoiningDate".


Ans: SELECT CONVERT(VARCHAR(20),JoiningDate,108) FROM [EmployeeDetail]

You might also like