File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes sql query regarding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "sql query regarding" Watch "sql query regarding" New topic

sql query regarding

Antonio Giovanni
Ranch Hand

Joined: Jun 27, 2005
Posts: 85
Firstly i am not an expert in SQL..

ok, if i want the recent log TIME on the recent DATE and corresponding data, i have a query like this:

I know the above query is very poor with many sub-queries.

What in your opinion would be the best way to handle such a query.. in the most optimized way? Your ideas please..

Thanks a bunch
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33124

Presumbably the timelog table is large and contains data for many employees. So the first optimization is to only go through that table once. Also, make sure you have an index on empid.

For example:

Different database have different ways of saying to just return the first row. Alternatively, you could set the JDBC fetch size to 1.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Antonio Giovanni
Ranch Hand

Joined: Jun 27, 2005
Posts: 85

wow, that's a clever way of getting what i wanted..

Thanks a bunch

I do have the table indexed.
I agree. Here's the link:
subject: sql query regarding
It's not a secret anymore!