Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL several sorting conditions: WHERE and LIMIT in the same query

Tags:

php

sorting

mysql

I have a database and i want to sort results like this:

$query1 = "SELECT * FROM pictures  LIMIT 0,10 "; 

    $result = mysql_query($query1);
            while($row = mysql_fetch_array($result))        
            echo $row['picture_rating'];

and

$query1 = "SELECT * FROM pictures  WHERE  column_name = 'column_text' "; 

    $result = mysql_query($query1);
            while($row = mysql_fetch_array($result))        
            echo $row['picture_rating'];

Both of the codes above are working properly, but when i want to use both condition at one time like this:

$query1 = "SELECT * FROM pictures  LIMIT 0,10 WHERE  column_name = 'column_text' "; 

it doesnt work. Any ideas how to make it work? Thanx!

SOLVED: Information that LIMIT should be after WHERE was exactly what i needed. Thanx to all.

like image 742
user2054618 Avatar asked Jan 28 '26 01:01

user2054618


1 Answers

the SQL syntax for SELECT defines that LIMIT should be after WHERE

see http://dev.mysql.com/doc/refman/5.0/en/select.html

like image 173
Puggan Se Avatar answered Jan 30 '26 14:01

Puggan Se



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!