This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes incorrect MAX result with query. (diagram photo included) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "incorrect MAX result with query. (diagram photo included) " Watch "incorrect MAX result with query. (diagram photo included) " New topic
Author

incorrect MAX result with query. (diagram photo included)

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Hi all,
I have the following SQL statement that returns the table-photo below:




I would like to get the *latest* note from each entity_id from the table (the resulted query).
For this I did:



but the results are incorrect. the max(note_date) is correct but not the note?!?!?!
any idea what am I doing wrong?

thanks

Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3740
    
  10

All records in a query result set must be uniform in type. Therefore, your combination "SELECT MAX(note_date),..." will not work since it should return the max note date and all records joined with in. If you want a single record you need to indicate that such as "select record where note_date = (select max(note_date))".


[OCA 8 Book] [Blog]
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
yep....thank you!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: incorrect MAX result with query. (diagram photo included)
 
It's not a secret anymore!