Friday, October 8, 2010

Some tricky SQL queries (Interview Questions)

1.Select nth highest salary and name from emp table
SELECT DISTINCT (a.empsalary),a.Employee_Name FROM empData A WHERE  N =(SELECT COUNT (DISTINCT (b.empsalary)) FROM empData B WHERE a.empsalary<=b.empsalary);
--where N is your number (2nd or 5th)
e.g SELECT DISTINCT (a.empsalary),a.Employee_Name FROM empData A WHERE  5 =(SELECT COUNT (DISTINCT (b.empsalary)) FROM empData B WHERE a.empsalary<=b.empsalary);

2.Select query without using "Like" operator . For eg select employee name start with 'j' and city is 'Noida' in company_name

select * from empdata where CHARINDEX('j',Employee_name)=1 and CHARINDEX('Noida',company_name)>0




3.Select query for grouping 2 coulmns in one column using Case statement

select result=case when p1 is not null then p1 when p2 is not null then p2 end from tbltest



4.Create identity like coulmn in query

select row_number () over( order by p1) as sno, result=case when p1 is not null then p1 when p2 is not null then p2 end from tbltest

36 comments:

  1. nice query......
    Thanks sir..

    ReplyDelete
  2. Mostly asked question in Interview..
    thanks bhaiya....

    ReplyDelete
  3. please post more of this kinds of questions.....

    ReplyDelete
  4. Hello,

    Above Help is Great.

    More Interview Sql Queries also available on:

    http://www.webslike.com/Thread-Most-Frequently-Asked-Complex-SQL-Queries-With-Solution-In-Interviews

    ReplyDelete
  5. Thanks for sharing use interview questions on .Net technology. While preparing for my job interview, your article helped me a lot to sharpen my skills and do well in my interview. one of trainer from leading dot net training institutes in Chennai suggests me about your site.

    ReplyDelete
  6. very nice blogs!!! i have to learning a lot of information for this sites...Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.Mysql Training in chennai | Mysql Training chennai | Mysql course in chennai | Mysql course chennai

    ReplyDelete
  7. Phone calls can be composed so that the calling party calls alternate members and adds them to the call; be that as it may, members are generally ready to call into the telephone call themselves by dialing a phone number that interfaces with a "meeting extension" (a specific sort of hardware that connections phone lines).
    Conference Calling Plugins

    ReplyDelete
  8. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. 
    java training in chennai | java training in bangalore

    java online training | java training in pune

    java training in chennai | java training in bangalore

    ReplyDelete
  9. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog. 

    python training in chennai | python training in bangalore

    python online training | python training in pune

    python training in chennai | python training in bangalore

    python training in tambaram | python training in velachery

    ReplyDelete
  10. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    python training in chennai
    python training in Bangalore
    Python training institute in chennai

    ReplyDelete
  11. Excellent blog, I wish to share your post with my folks circle. It’s really helped me a lot, so keep sharing post like this
    python training in velachery
    python training institute in chennai

    ReplyDelete
  12. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.

    AWS Interview Questions And Answers

    AWS Training in Bangalore | Amazon Web Services Training in Bangalore

    Amazon Web Services Training in Pune | Best AWS Training in Pune

    AWS Online Training | Online AWS Certification Course - Gangboard

    ReplyDelete
  13. Thanks first of all for the useful info.
    the idea in this article is quite different and innovative please update more.
    best android institute in bangalore
    Android Training in chennai
    Android Training in Vadapalani
    Android Training in Padur

    ReplyDelete
  14. After reading your post I understood that last week was with full of surprises and happiness for you. Congratz! Even though the website is work related, you can update small events in your life and share your happiness with us too.
    devops online training

    aws online training

    data science with python online training

    data science online training

    rpa online training

    ReplyDelete
  15. Thank you for sharing such a nice and interesting blog with us regarding Java. I have seen that all will say the same thing repeatedly. But in your blog, I had a chance to get some useful and unique information. I would like to suggest your blog in my dude circle.
    Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

    ReplyDelete
  16. Its a wonderful post and very helpful, thanks for all this information. You are including better information regarding this topic in an effective way



    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery






    ReplyDelete
  17. Really Good blog post.provided a helpful information.I hope that you will post more updates like this.. oracle training in chennai

    ReplyDelete
  18. Thank you for posting informative insights, I think we have got some more information to share with! Do check out oracle dba training in chennai and let us know your thoughts. Let’s have great learning!

    ReplyDelete
  19. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet
    effective. A lot of times it’s very hard to get that “perfect balance”
    between superb usability and visual appeal. I must say you’ve done a
    very good job with this.
    oracle dba training in Chennai
    best java training in Chennai
    node js certification training in Chennai

    ReplyDelete
  20. Great post. keep sharing such a worthy information.
    AWS Training in Chennai

    ReplyDelete
  21. it is really explainable very well and i got more information from your blog.

    ReplyDelete