Consider a database table R with attributes A and B. Which of the following SQL queries is illegal ?
(A) SELECT A FROM R;
(B) SELECT A, COUNT(*) FROM R;
(C) SELECT A, COUNT(*) FROM R GROUP BY A;
(D) SELECT A, B, COUNT(*) FROM R GROUP BY A, B;
Answer: (B)
Explanation: SELECT A FROM R; legal query
SELECT A, COUNT(*) FROM R; Illegal query because we can’t SELECT A, COUNT(*) unless it is grouped by A.
SELECT A, COUNT(*) FROM R GROUP BY A; legal query
SELECT A, B, COUNT(*) FROM R GROUP BY A, B; legal query
So, option (B) is correct.
Quiz of this Question
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
11 Apr, 2018
Like Article
Save Article