2
임의의 행을 선택해야하는 상당히 큰 sql 쿼리가 있습니다. 테이블 크기가 크기 때문에 rand()에 의한 정렬은 실제로 길어집니다.임의의 행을 가져 오지만 ORDER BY RAND()는 사용하지 마십시오. MariaDB
$getdata = $this->db->query("
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') as 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'
$home $q limit $limit offset $start");
이 검색어에 대해 임의의 행을 선택하는 가장 좋은 해결책은 무엇입니까?
먼저 임의의 숫자 목록을 생성 한 다음 목록에 포함 된 행만 선택할 수 있습니까 (예 : #rown 또는 일부 항목에 가입). 당신이 실제로 아무것도 정렬하지 않는 그런 식으로. (난수 목록 생성은 http://stackoverflow.com/questions/1045138/how-do-i-generate-random-number-for-each-row-in-a-tsql-select에서 확인할 수 있습니다) – johnjps111