1

if i had 10 rows which fits this description on mysql

SELECT id, nav, img 
FROM mytable 
WHERE id='$id' 
ORDER BY pageDisplayNum ASC;

pageDisplayNum may not be in numeric order, meaning 1, 2, 5, 10, 16, 22 etc...
q: how can i choose the 3rd or 6th item from this list

the index number would be coming in from php as a variable
i read about TOP but this didnt work either

SELECT TOP $num 
id, nav, img 
FROM mytable 
WHERE id='$id'
ORDER BY pageDisplayNum ASC;
1
  • What database are you using? The best answer is to use the row_number() function, but mysql does not support this function. Instead you have to use a self-join. Commented May 13, 2012 at 3:43

2 Answers 2

2

This for 7th item

SELECT id, nav, img 
FROM mytable 
WHERE id='$id' 
ORDER BY pageDisplayNum ASC;
LIMIT 6,1

You can add LIMIT offset,row_count query

Sign up to request clarification or add additional context in comments.

1 Comment

You might want to change offset to 5. LIMIT 6, 1 will output 7th row, not 6th.
1

You can use LIMIT <offset>, <#rows> To select the row you want:

SELECT id, nav, img 
FROM mytable 
WHERE id='$id' 
ORDER BY pageDisplayNum ASC
LIMIT 2, 1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.