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:
Output after run the above queries.
If you have another solution then please comment.. I will post here..
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
If you have another solution then please comment.. I will post here..
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.
ReplyDeleteGreat list of questions! Here's a few more I think you should consider adding to your list too:
ReplyDeletehttp://cc.davelozinski.com/general/tricky-csharp-and-sql-interview-questions
_
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.
ReplyDeletehepl me!
ReplyDeletehai
ReplyDeletei have t1 and t2 table
t1 have
a
b
c
d
=====
t2 have
c
d
e
f
i want to join two tables .....
so i want innerjoin, left,right join output....
No need for temp table you can simply do this.
ReplyDeleteupdate t1
set Name = (select t22.Name from t2 t22 where t1.ID=t22.ID)
They are tricky indeed. It was nice to read this article about them. Nice job.
ReplyDelete