1 1 vote Databases databases sql + – Rahul Jain25 2.8k views answer comment Share Follow Print See all 6 Comments 6 6 Comments reply Show 3 previous comments Rahul Jain25 commented Oct 5, 2016 reply Follow flag D is given 0 0 replyShare Habibkhan commented Oct 5, 2016 reply Follow flag Ya it is going to be D.Just go through the link which I have mentioned and read the most voted answer.I hope it will clear your doubts if any 0 0 replyShare Rahul Jain25 commented Oct 5, 2016 reply Follow flag Thanks 0 0 replyShare Please log in or register to add a comment.
2 2 votes Here the main confusion that is created is between option B and D. As we know SELECT statement can return duplicates , so is the case here. Suppose u have 6 values 1,2,3,4,5,5 then the query mentioned in option B will return all the 6 tuples i.e. 5,5,4,3,2,1 whereas if you use query mentioned in option D , it will return 5,4,3,2,1. Plz consult this link :(This may help you further and remove any further doubt if you have) http://stackoverflow.com/questions/20853725/what-is-the-use-of-with-ties-keyword-in-select-statement-in-sql-queries Hence the correct option to the above question would be option D. Habibkhan answered Oct 5, 2016 Habibkhan comment Share Follow See all 2 Comments 2 2 Comments reply Rahul Jain25 commented Oct 5, 2016 reply Follow flag I dont agree with you. 5,5 will be considered in both bcoz Top with ties and Top differ only if last item has duplicate. 0 0 replyShare Habibkhan commented Oct 5, 2016 reply Follow flag That is why I m saying u have to consider all cases.A case may occur where last item may have duplicates.In that case B) option would be wrong 1 1 replyShare Please log in or register to add a comment.
1 1 vote Option B is Correct for functionality of TOP with TIES refer http://stackoverflow.com/questions/20853725/what-is-the-use-of-with-ties-keyword-in-select-statement-in-sql-queries Shubham Pandey 2 answered Oct 5, 2016 Shubham Pandey 2 comment Share Follow See all 7 Comments 7 7 Comments reply Show 4 previous comments Shubham Pandey 2 commented Oct 5, 2016 reply Follow flag @habibkhan pls read the link again 0 0 replyShare Habibkhan commented Oct 5, 2016 reply Follow flag Read all the answers properly . WITH TIES along with ORDER BY clause is not removing duplicacy I agree but WITH TIES along with ORDER BY DESC is removing duplicacy. 0 0 replyShare Habibkhan commented Oct 5, 2016 reply Follow flag Ya I have checked.I request you to read the answer by Adriaan Stander which is most voted.There also it is written. 0 0 replyShare Please log in or register to add a comment.
0 0 votes D is correct B has wrong syntax after from its missing orders collumn name rather it writes orderby directly. optin c will not give the answer sorted hence top 5 can be any value gourav_banerjee answered Nov 29, 2016 gourav_banerjee comment Share Follow 0 reply Please log in or register to add a comment.