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 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Sql query" Watch "Sql query" New topic

Sql query

manish gupta
Ranch Hand

Joined: Nov 06, 2005
Posts: 36
Hi ,

I want to know the query to get the first record of table

like select first recorf from "table" orderby

Please help me in this.

Thanks with regard
Chad Clites
Ranch Hand

Joined: Aug 16, 2005
Posts: 134
Try "SELECT * FROM table LIMIT 1;"
[ June 13, 2007: Message edited by: Chad Clites ]
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42959
Note that SQL has no notion of an implicit ordering of records, so there is no designated "first record". The "LIMIT 1" technique will ensure that you'll get back exactly one record, but it could be a different one every time you call it. To make sure you get the desired record, sort the results so that the record you're looking for is indeed at the top, something like "SELECT * FROM table ORDER BY my_criterium LIMIT 1".
I agree. Here's the link:
subject: Sql query
It's not a secret anymore!