I have the following query
$samecars = $this->QueryResult("SELECT * FROM carads where STATUS='1' and DEL='0'
and TITLE !='' and IMAGE1 != '' and IMAGE1 != '-1' and PRICE BETWEEN $pricelow
and $pricehigh order by RAND() LIMIT 0,3");
When I remove RAND()
the query is executed almost instantly, if I add the RAND()
it takes about 10-30 seconds.
There are about 1 million rows in the table carads. I need RAND() in order to use random displaying.
More details:
QueryResult
looks like this
public function QueryResult($strQuery) {
$this->connector();
$query = mysqli_query($this->link, $strQuery);
$arr = array();
if ($query) {
while ($result = mysqli_fetch_object($query)) {
array_push($arr, $result);
}
}
$this->close();
return $arr;
}
ALSO I tried add in SQL the following example command
SELECT * FROM carads where STATUS='1' and DEL='0'
and TITLE !='' and IMAGE1 != '' and IMAGE1 != '-1' and PRICE BETWEEN 8000
and 15000 order by RAND() LIMIT 0,3"
and RAND() is highlighted red and when i execute it through #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"' at line 3