I have an sql statement which works, but when I want to add Order By clause, then the query stops working.
The query below works fine:
SELECT DISTINCT property.id
, property.unid
, property.imported
, property.userid
, CONCAT(user.firstname) as username
, property.url
, IFNULL(user.thumbpic,'temp/misc/noimage.png') as profilepic
, property.bedrooms
, property.beds
, type.meta_val as type
, property.accommodates
, property.price
, IFNULL (
(SELECT thumbimg
FROM tblpropertyimages
WHERE pid = property.id
LIMIT 1
)
, 'temp/misc/noimage.png'
) image
, property.name as propertyname
, ( SELECT SUM(rating) FROM tblreviews WHERE pid = property.id ) as totalrating
, ( SELECT COUNT(id) FROM tblreviews WHERE pid = property.id) as countratings
, location.name as cityname
FROM tblproperty as property
JOIN tbluser as user
ON property.userid = user.id
JOIN tblcommon as type
ON property.type = type.id
LEFT
JOIN tblpropertyamenities as p_amenities
ON property.id = p_amenities.pid
JOIN tbllocation as location
ON location.id = property.city
WHERE property.status = 'Active'
AND user.status = 'Active'
AND property.price >= 0
AND property.price <= 10000
LIMIT 9
OFFSET 0
However, If i add this line to the end of the statement:
ORDER BY property.price ASC
Then the query stops working, any idea why this ORDER BY clause is causing the error?