jlrdw's avatar
Level 75

Anyone else having wrong results from MySql MAX

With this data:

If I run:

SELECT MIN(`checkid`) AS cid, transdate, transdescribe, widthdraw, deposit, isclr FROM checks WHERE isclr = 0

MIN gives me the entire correct row:

However using MAX:

SELECT MAX(`checkid`) AS cid, transdate, transdescribe, widthdraw, deposit, isclr FROM checks WHERE isclr = 1

Gives correct checkid, but other fields are wrong, it gives max amount instead.

0 likes
7 replies
Sinnbeck's avatar

You are still getting the first row I think

can you try

SELECT MAX(`checkid`) AS cid, transdate, transdescribe, widthdraw, deposit, isclr FROM checks WHERE isclr = 1 ORDER BY checkid DESC
jlrdw's avatar
Level 75

@Sinnbeck same result, the MIN gives correct row. Max gives correct checkid, but other data is from max amount row, see images.

sr57's avatar

complement to @tykus

@jlrdw try postgresql

You should not be able to write such query.

jlrdw's avatar
Level 75

@sr57 I am only after the date that goes with that row anyway, eventually the queries will be converted in laravel where parameters are used, so I will just use 2 queries, one to get max, and from the checkid another to get date for the row.

Please or to participate in this conversation.