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
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply 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
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3652

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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: incorrect MAX result with query. (diagram photo included)
 
Similar Threads
simple MAX SQL returns wrong result (!)
how to find out 3rd max salary from an emp table?
Select an entity object in a NamedQuery
select distinct
getting last row