好的,所以我有以下架构和查询,由于 ORDER BY,它非常慢(使用真实数据时):
http://sqlfiddle.com/#!2/5e7bb/10
根据 mysql man :“您正在连接许多表,并且 ORDER BY 中的列并不全部来自用于检索行的第一个非常量表。(这是 EXPLAIN 输出中的第一个表,它不有一个 const 连接类型。)“
但我仍然需要按该列排序。我需要怎么做?
最佳答案
更新:自从 fiddle 更新后:
SELECT
cpa.product_id,
cp.product_internal_ref,
cp.product_name,
cpa.product_sale_price,
cpa.is_product_service,
cpa.product_service_price
FROM
catalog_products_attributes cpa
JOIN
catalog_products cp ON cp.product_id = cpa.product_id
WHERE
cpa.product_id IN (
SELECT
product_id
FROM
catalog_products_categories
WHERE
category_id = 41
)
ORDER BY
cpa.product_service_price DESC
关于连接表中的 mySQL ORDER BY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16786940/