Which of the following statement is correct about the following SQL query?
SELECT CourseName, Fees, StartDate, Duration FROM Students, Courses
WHERE Students.CourseID = Courses.CourseID
GROUP BY BookID

This question was previously asked in
Beltron Programmer 1 Oct 2023 Official Paper
View all BELTRON Programmer Papers >
  1. It is a wrong query as attribute in the group by clause is not specified in the select clause.
  2. It is a wrong query since is used in place of
  3. It is a wrong query as multiple tables are used in the SELECT clause.
  4. It is correctly formed query.

Answer (Detailed Solution Below)

Option 1 : It is a wrong query as attribute in the group by clause is not specified in the select clause.
Free
Beltron Programmer Mock Test
0.8 K Users
20 Questions 20 Marks 24 Mins

Detailed Solution

Download Solution PDF

The correct answer is Option 1) It is a wrong query as attribute in the GROUP BY clause is not specified in the SELECT clause.

Key Points

  • In SQL, when using the GROUP BY clause, all selected columns that are not aggregated must appear in the GROUP BY clause.
  • In the given query:
    SELECT CourseName, Fees, StartDate, Duration 
    FROM Students, Courses 
    WHERE Students.CourseID = Courses.CourseID 
    GROUP BY BookID
  • BookID is used in the GROUP BY clause but is not present in the SELECT list, and it is also not a part of any aggregation (like COUNT(), SUM(), etc.).
  • This violates the SQL standard rule and will result in an error in most RDBMS systems like MySQL, PostgreSQL, and SQL Server.

Additional Information

  • Option 2 – It is a wrong query since is used in place of: This statement is unclear and grammatically incorrect; it doesn’t specify any real SQL issue.
  • Option 3 – It is a wrong query as multiple tables are used in the SELECT clause: Not true. Joining multiple tables using WHERE is valid SQL.
  • Option 4 – It is correctly formed query: ❌ Incorrect. The mismatch between SELECT and GROUP BY columns makes the query invalid.

Conclusion: The SQL query is incorrect because it uses GROUP BY on a column that is neither in the SELECT clause nor used in an aggregate function.

Latest BELTRON Programmer Updates

Last updated on Nov 25, 2024

-> BELTRON Programmer 2024 Notification has been released on the official website.

-> The Bihar State Electronics Development Corporation Limited (BELTRON) has announced a recruitment drive for Programmer positions on a contractual basis.

-> Specific vacancy details will be shared separately.

-> Interested candidates can apply online from November 11, 2024, to December 10, 2024.

-> The Minimum age of the candidates should be 21 years and maximum age should be 59 year of age. 

Get Free Access Now
Hot Links: teen patti gold teen patti master gold download teen patti master golden india teen patti star apk