Click to See Complete Forum and Search --> : MySQL - Select bny Row index?


Inx51
12-13-2009, 06:44 PM
Hi!
Is there any way to select by the rows index?..I dont want to use any counter or such in the actuallt table..

For instance I whould like to do the following(this is pseudo)

"SELECT * FROM mytable WHERE ROW_INDEX=0"

and then the database whould select the very first row...

is there any smart way to do this?

Thanks in advance!

ssystems
12-16-2009, 11:17 PM
Would be nice to know what database you're using. Row Number (http://www.databasejournal.com/features/mssql/article.php/3572301/RowNumber-function-in-SQL-Server-2005.htm)

NogDog
12-17-2009, 01:28 PM
In any normalized database design, the physical(?) row number should be essentially meaningless: it's just the arbitrary order in which the DBMS stored it. If you have some sort of auto-incremented integer field as the primary key, then it would be a pretty simple matter to grab one via something like:

SELECT * FROM table_name ORDER BY pk_col LIMIT 1 OFFSET 0

(Change the OFFSET value to get the Nth record after the first.)