Monday, 9 November 2015

TRICKY SQL INTERVIEW QUERIES QUESTIONS ANSWERS FOR EXPERIENCED SQL DEVELOPERS

Hey guys, I am writing this post after many days, after many comment by SQL Guys, Every one want to see new post related to SQL Interview questions, I have already written many Sql interview queries, In the bunch which are related, So the visitor looking for new queries so in this post, at a time I cant post many but, keep posting new query which I will face.
So for new tricky queries I need you help, If you have any tricky Sql queries then please post as a comment. It will be helpful for other.

So lets discuss new a query, This is not new but little bit tricky.

Query : There are two tables T1 and T2 with two columns, I want to swap the name of both tables, based on ID column. How you will do that.
Tables:


Ans:
--First copy T1 data in to temp table
SELECT * INTO #T1 FROM T1
--Then Update T1 with T2
UPDATE T1 SET T1.NAME = T2.NAME FROM T1 INNER JOIN T2 ON T1.ID = T2.ID

--Then Update T2 With Temp talbe(#T1)
UPDATE T2 SET T2.NAME = #T1.NAME  FROM T2 INNER JOIN #T1 ON T2.ID = #T1.ID

DROP TABLE #T1 --Drop temp table Table

Output after run the above queries.
If you have another solution then please comment.. I will post here..
Visit Our New Site for HR Interview Questions Answers http://www.interviewboat.com/Company/GetCompany
Sponsored Ads

4 comments:

  1. Would you please email me the PDF for Set 15, theoretical answers PDF. My email is fatima.s417@gmail.com. Your site is very informative.

    ReplyDelete
  2. Great list of questions! Here's a few more I think you should consider adding to your list too:
    http://cc.davelozinski.com/general/tricky-csharp-and-sql-interview-questions

    _

    ReplyDelete
  3. your article is very nice i like this article and i would like to get from more information about this article please keep sharing this. i am a writer working with phd thesis writing service. thesis writing help to all students. this is very effective one.

    ReplyDelete