This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JDBC 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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "sql query regarding" Watch "sql query regarding" New topic
Author

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30392
    
150

Antonio,
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.


[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
Jeanne,

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: http://aspose.com/file-tools
 
subject: sql query regarding