English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

May I know the sentence expressing the following query?

SELECT course.course_code, title
FROM course, assignment
WHERE course.course_code = assignment.course_code
GROUP BY title, course.course_code
HAVING COUNT(*) >= ALL ( SELECT COUNT (*)
FROM assignment
GROUP BY course_code)


course
course_code title credit quota
c1 Logic 60 null
c2 Syntax 30 null
c3 Functions 60 null
c4 Semantics 60 24
c7 Pragmatics 30 20

assignment
student_id course_code assignment_no grade
s01 c4 1 74
s01 c4 2 78
s01 c4 3 70
s05 c2 1 78
s05 c2 2 63
s07 c4 1 91
s09 c2 1 92
s09 c2 2 76
s09 c3 1 80
s09 c3 2 81
s09 c4 1 85
s09 c4 2 80
s09 c4 3 71
s09 c7 1 74
s09 c7 2 73
s10 c3 1 48
s10 c3 2 50
s10 c4 1 45
s10 c4 2 47
s10 c4 3 45
s57 c2 1 73
s57 c2 2 69
s57 c3 1 56
s57 c3 2 72
s57 c3 3 81
s57 c4 1 71
s57 c4 2 77
s57 c4 3 67

2007-04-21 17:13:37 · 1 answers · asked by Anonymous in Computers & Internet Programming & Design

1 answers

First, your SQL statement has some errors in it, namely in that you don't qualify the title column as belonging to the course table. This query is also a very inefficient way to get the information your after.

A better, more efficient query would be:

SELECT c.course_title, c.title FROM course c LEFT JOIN assignment a ON a.course_code = c.course_code GROUP BY c.course_title, c.title HAVING a.course_code IS NOT NULL

That said, here's a sentence describing your query:

Get all the course codes and titles from the course table, wherever there is an assignment for that course in the assignment table.

2007-04-21 17:34:13 · answer #1 · answered by Anonymous · 0 0

fedest.com, questions and answers