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 sql query regarding 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 "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: 32312

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]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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!