my dog learned polymorphism*
The moose likes JDBC and the fly likes Sql query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Sql query" Watch "Sql query" New topic
Author

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
Manish
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
Marshal

Joined: Mar 22, 2005
Posts: 41106
    
  45
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".


Ping & DNS - my free Android networking tools app
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Sql query
 
Similar Threads
extracting data from two table and populating them in a drop down box
Complex SQL Query
Hibernate in Acion- Page-269- Understanding the implicit join-
Rownum in DB2 V 7.2 - Mainframe
Create table error