0

我有这个查询,它通过 focus.name ASC 对其进行排序来返回结果。我想对此进行扩展,首先按 rand() 排序,然后按 focus.name 排序并将其限制为 10。

$query = mysqli_query($db,"SELECT * FROM vendor_products WHERE 
vendor_products.focus_id IN (SELECT focus.id FROM focus WHERE
focus.name='".mysqli_real_escape_string($db,$focus_name)."' AND 
mydelete='0' ORDER BY focus.name ASC) AND product_id='".mysqli_real_escape_string($db,$product['id'])."' 
AND mydelete='0' ORDER BY focus_id ASC");
4

1 回答 1

2

做这样的事情

select t1.* 
from table t1, (select id from table order by rand() limit 10) t2
where t1.id = T2.id
order by t1.name

这里

于 2012-06-21T17:17:47.107 回答