1

How would I select all but the first 3 rows in my MySql query?

$query = mysql_query("SELECT * FROM comments WHERE approved = 1");  
3
  • According to what criterion do you define "first"? Commented Jul 7, 2010 at 5:35
  • Well i'd like it to be work regardless of how I ordered or sorted it. Commented Jul 7, 2010 at 5:38
  • possible duplicate of Mysql Offset Infinite rows Commented Jul 7, 2010 at 5:40

3 Answers 3

2
SELECT * FROM comments WHERE approved = 1 LIMIT 3,SOME_HUGE_NUMBER

See this post for more info

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

Comments

2

Do you want the following:

$query = mysql_query("SELECT * FROM comments WHERE approved = 1");
$rowCount = 0;
while ($row = mysql_fetch_assoc($query)) {
    $rowCount = $rowCount + 1;
    // do stuff only if you have reached the third row.
    if ($rowCount > 3){
        // do stuff here
    }
}

Comments

0
$query = mysql_query("SELECT * FROM comments
                                     WHERE approved = 1 
                                     ORDER BY columnName 
                                     LIMIT 3");

To find third record order by columnName use

$query = mysql_query("SELECT * FROM comments
                                     WHERE approved = 1 
                                     ORDER BY columnName 
                                     LIMIT 2, 1");

To find All other than 1st 3 rows use LIMIT 2, total_no_of_rows

if you don't know total_no_of_rows use very large number instead of it.

$query = mysql_query("SELECT * FROM comments
                                     WHERE approved = 1 
                                     ORDER BY columnName 
                                     LIMIT 2, total_no_of_rows");

1 Comment

This is all but the first 2.

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.