English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

suppose there's a hundred product with x=a

this query will return the FIRST item

SELECT TOP 1 product_name FROM table_name WHERE x='a'

Now how do i get the second, third, fourth... i dont know the id of the fields, i dont know any other elemets in the table.

2007-02-28 20:12:26 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

4 answers

Clearly you are using Transact-SQL, so the previous answer utilizing the OVER clause is correct.

In MySQL, you can provide an offset to the LIMIT predicate:

SELECT prroduct_name FROM table_name WHERE x = 'a' LIMIT (1,1)

LIMIT (1,1) would give the second record; LIMIT(2, 1) would give the third; LIMIT (3, 1) would give the fourth, etc.

2007-03-01 01:14:03 · answer #1 · answered by Anonymous · 1 0

It is predicated upon the variety you're construction the question. i'm not an sq. jockey so I maximum oftentimes use OO3.a million Base layout View. There are field choose and variety possibilities that enable me a good looking intense degree of specificity in construction queries. You positively could get those extra fields out of there to diminish down you're loading situations.

2016-10-17 00:11:55 · answer #2 · answered by ? 4 · 0 0

It depends on the Database.

For SQL Server it would be

SELECT product_name FROM ( SELECT Row_Number() OVER (ORDER BY product_name) as rowid, product_name FROM table_name WHERE x='a') as T where rowid = yyyyy


replace yyyyy with your desired row number
Good Luck
M.

2007-02-28 20:19:58 · answer #3 · answered by Martin G. 4 · 0 2

try to use a "cursor"

2007-02-28 21:03:14 · answer #4 · answered by abd 5 · 0 3

fedest.com, questions and answers