What’s wrong in the following query?

In this forum you can discuss database related issues which can be wxWidgets related, but also generic in nature.
Post Reply
malisha21
In need of some credit
In need of some credit
Posts: 1
Joined: Sat Jun 25, 2016 7:45 am

What’s wrong in the following query?

Post by malisha21 »

SELECT student_code, name
FROM students
WHERE marks =
(SELECT MAX(marks)
FROM students
GROUP BY subject_code);
pls suggest me for this
i am stuck here
User avatar
doublemax
Moderator
Moderator
Posts: 19102
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: What’s wrong in the following query?

Post by doublemax »

What's the table structure for "students"?
Use the source, Luke!
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: What’s wrong in the following query?

Post by iwbnwif »

... and what is the problem you are having, and which database are you using (may or may not be relevant)?

Code: Select all

SELECT student_code, name
FROM students
WHERE marks = 
(SELECT MAX(marks)
FROM students
GROUP BY subject_code);
For a start, the GROUP BY clause is probably redundant because MAX(marks) should only return a single result in the sub-query, did you mean:

Code: Select all

SELECT student_code, name
FROM students
WHERE marks = 
(SELECT MAX(marks)
FROM students)
GROUP BY subject_code;
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
User avatar
marcelinux
Knows some wx things
Knows some wx things
Posts: 40
Joined: Thu Nov 07, 2013 9:59 pm
Location: Madrid, Spain

Re: What’s wrong in the following query?

Post by marcelinux »

malisha21 wrote:SELECT student_code, name
FROM students
WHERE marks =
(SELECT MAX(marks)
FROM students
GROUP BY subject_code);
An agregate function need explicit all others columns in the table:
... GROUP BY subject_code, student_code, name;
isn't it?
I just need learn a little bit more. Thank you for your help.
Post Reply