You can also use a row number variable:
SELECT * FROM (
SELECT t.*,
@rownum = @rownum + 1 AS rank
FROM TABLE t, (SELECT @rownum := 0) r
ORDER BY ID
LIMIT 0, 34
) Q
WHERE rank in (3, 5, 9, 20, 34)
I'd try to use the LIMIT
smartly otherwise it will scan your whole table every time.
Based on your description of your scenario...
my scenario: I need to delete only a single row... there are several identical rows.. so using a delete with a where clause would delete all of them. Also, say there are 5 identical rows.. and i need to delete the third of those 5 rows...
You really need to be careful with this otherwise you delete the wrong rows. Think of a good criterium that would distinguish the rows that you want to delete from the other rows, say.. do you want to delete the newest, or all except the newest...
You can use an extended version of the @rownum trick to delete the Nth from each group.. but before I go into that it would be better to know more about your specific problem.
Ah now here comes the monkey out of the sleeve:
Suppose there are 5 identical rows.. the user clicks on the 3 rd row and asks that to be deleted... a where query won't be efficient as it deletes the first row that matches the where clause or all rows that match it.. how is that i delete only the third row and leave all others intact..???
Forget all I said. You need an AUTO_INCREMENT
field in your table, uniquely identifying your records. Then you can use DELETE FROM table WHERE id = $id
. Thanks to OMG Ponies for the OP therapy ;)