aspose file tools*
The moose likes JDBC 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
JavaRanch » Java Forums » Databases » JDBC
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: 3716
    
    5

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))".


My Blog: Down Home Country Coding with Scott Selikoff
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
yep....thank you!
 
jQuery in Action, 2nd edition
 
subject: incorrect MAX result with query. (diagram photo included)