Thursday, 19 May 2016

Tricky sql interview questions and answer

Guys generally we see that interviewer asked very easy question but question is very tricky. Even questions are very easy but bit difficult to give the answer. Here I am sharing a collection of tricky sql interview question.
1.       What will be the output of Select $
Answer: 0.0

Remember that only $ special character sql is returning the value for other special character it will giving error.
  
2.       What will be the Output of 
Select Count (*)


A count by definition has to return a value, so our query implicitly has one row in it. The result of the count is returning 1. SQL Server is effectively applying a form to a dummy table, which has only one row. Thus you will get 1 for your count. It is similar to DUAL table in Oracle, SYSDUMMY1 in DB2.
3.       What will be the Output of the below sql script
Select Count (‘88’)
Select Count (88)

Both are returning 1.


4.       What will the output of
Select (select ‘Bagesh’)
  
If select statement is in () then it will be treated as derived table.
  
5.       What will the output of the below sql script

Select Select ‘Bagesh’
  
If select statement is in () then it will be treated as derived table. If there is no () it will throw syntax error

6.       What will be the out of the below sql script.
Select Sum (1+4*5)



Select Max(1+4*5)



Select Max(‘Bagesh’)



7.       What will the output of below sql script
Select 1 + NULL


If we add anything on NULL the all value will be NULL. Suppose if we have null value then we need to replace null value to some other value and then we will do any operation. With the help of ISNULL () we replace the null value.
  
Above example I replace null value to 0.

8.       What will the output of below sql script
Select Case when NULL=NULL
Then ‘Yes’ else ‘No’ end as Result

Because two null value never same.


9.       What will the output of below sql script
Select top 2 1 ‘3’
  
3 will the column name and 1 is the value.
  
Syntax of top clause [Top 2] and the 1 is value and [‘3’] as column name
Same sql script we will write like
Select top 2 1 as ‘3’

10.   How to insert 100 records in a table without using loop.

Insert into Emp (ID,Name) values (1,’Bagesh kumar singh’)
Go 100
  
11.    For 9/2 I want the result as 4.5 write the sql script
For getting the desirer output first we need to convert the number to float.
  

12.   How we find the number of character occurs in a string for example in Bagesh Kumar Singh how many ‘a’ character occurs.


Read More tricky sql  interviews questions and answer: Click here 
https://www.deskbright.com/sql/sql-interview-questions/



8 comments: