PDA

View Full Version : pulling my hair out


the moose
11-13-2008, 07:44 PM
whats going on...???

my table is like this:

a - int
b - int
c - int
d - varchar
e - varchar
f - varchar

some data in the table
a b c d e f
1 1 1 6 2 5
2 1 2 3 5 4
3 2 1 8 6 1
4 2 2 4 6 9

what i have at the moment as a SQL Query (MySQL) is:


SELECT a, MAX(d) FROM table_name WHERE c = 2


i should be getting the results to be:
a MAX(d)
4 4

i'm not!

whats going on with my query???

Cheers

The Moose

tomws
11-13-2008, 08:57 PM
Well, what are you getting instead?

Fumigator
11-13-2008, 10:52 PM
You are using a group function MAX() with no GROUP BY clause, so MySQL assumes you're grouping on all rows in the table. Your WHERE clause doesn't limit the MAX() results.

http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html

guelphdad
11-13-2008, 11:50 PM
Please use meaningful thread titles. Yours did not explain what the thread is about.