It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes Interesting info about 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 "Interesting info about "select with order by"" Watch "Interesting info about "select with order by"" New topic

Interesting info about "select with order by"

Syed Zackriya Hussainy
Ranch Hand

Joined: Jun 24, 2002
Posts: 30
hi alls,
This site has helped me in many ways, so thought of sharing something which is really important for ppl using JDBC.
if u use the order by clause with select query, your ResultSet will only be able to fetch first few records.
eg: select user_name from emp order by sno
If you execute the above query i am sure u will be perplexed to see its not working.
use the query like this.
select * from (select user_name from emp order by sno)
then it will work
hope its useful to all, any further queries plzz feel free to ask
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Really? I have never had any problems with the select statement using order by. This may have to do with your DB and/or DB driver.

So much trouble in the world -- Bob Marley
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
I've never had any problems either. You might want to run your original query in your sql editor and see how it compares to your ResultSet. I think something else is going on

Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
I agree. Here's the link:
subject: Interesting info about "select with order by"
It's not a secret anymore!