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/



10 comments:

  1. Replies
    1. Hi Bru,


      Great info! I recently came across your blog and have been reading along.
      I thought I would leave my first comment. I don’t know what to say except that I have


      I wanted to know if we should go for SQL Always-on AG or FCI for SharePoint environment. We are planning to host the whole SharePoint environment in Azure IaaS.
      what are the pros and cons of SQL Always-on AG and FCI in Azure Iaas for SharePoint.
      I read multiple articles and watched many videos about how to use this tool - and was still confused! Your instructions were easy to understand and made the process simple.


      Thanks,

      Delete
  2. Great collection of question and answers thank you for sharing. Follow the link if you want OBIEE Online Training

    ReplyDelete
  3. • Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating. Power Bi Online Training

    ReplyDelete