aspose file tools
The moose likes JDBC and the fly likes simple MAX SQL returns wrong result (!) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "simple MAX SQL returns wrong result (!) " Watch "simple MAX SQL returns wrong result (!) " New topic
Author

simple MAX SQL returns wrong result (!)

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Can't figure it out why the MAX return-result is incorrect.

here's my table result (composed of 2 tables)



I would like to get the highest bidder, for this I'm using the MAX:


but the result is:



Why? the highest bidder is Tony Soprano not DELL
Amit M Tank
Ranch Hand

Joined: Mar 28, 2004
Posts: 257
because 745 is greater than other numbers of the coulmn. seems there is something fundamentally wrong in your question.


Amit Tank
Linked In
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
seems there is something fundamentally wrong in your answer :-)

if 745 is the highest bid why the result for *legal_name* is dell and not * tony soprano* and how do I correct this?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32708
    
    4
ORDER BY

?

I think you are choosing the highest bid for each of the bidders, not the highest bid of all.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26193
    
  66

Peter,
I think you want something more like this:


The max check is in the where clause so it hones in on the record you are looking for. (I didn't run this, so the syntax might be a bit off.)


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
yes, you are correct. the 'MAX' should be on the 'WHERE'.

THANK YOU!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: simple MAX SQL returns wrong result (!)
 
Similar Threads
Suggestions for Buying new laptop
Relationship between Bid and User
incrementing numbers in database when a new object is added
A session bean class must not have a superclass that is itself a session bean class.
blog of Kathy - Pair Programming is NOT always a choice