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.
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?

Postby malisha21 » Sat Jun 25, 2016 7:47 am

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: 11387
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: What’s wrong in the following query?

Postby doublemax » Sat Jun 25, 2016 7:56 am

What's the table structure for "students"?
Use the source, Luke!

iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 257
Joined: Tue Mar 19, 2013 8:52 pm

Re: What’s wrong in the following query?

Postby iwbnwif » Sat Jun 25, 2016 7:52 pm

... 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.10, TDM MinGW64 5.1.0, g++ 4.8.2, Ubuntu 16.04LTS, 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: 32
Joined: Thu Nov 07, 2013 9:59 pm
Location: Madrid, Spain

Re: What’s wrong in the following query?

Postby marcelinux » Tue Jun 28, 2016 9:01 am

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.


Return to “Database Related”

Who is online

Users browsing this forum: No registered users and 1 guest