简体   繁体   English

连接表中的mySQL ORDER BY

[英]mySQL ORDER BY in joined tables

Ok, so i have the following schema and query which is very slow (when using real data) because of the ORDER BY: 好的,由于ORDER BY,我具有以下非常慢的模式和查询(使用真实数据时):

http://sqlfiddle.com/#!2/5e7bb/10 http://sqlfiddle.com/#!2/5e7bb/10

As per mysql man : "You are joining many tables, and the columns in the ORDER BY are not all from the first nonconstant table that is used to retrieve rows. (This is the first table in the EXPLAIN output that does not have a const join type.) " 按照mysql man的说法:“您正在联接许多表,并且ORDER BY中的列并非全部来自用于检索行的第一个非恒定表。(这是EXPLAIN输出中的第一个没有const的表连接类型。)“

but i still need to sort by that column. 但我仍然需要按该列排序。 How would i need to do this ? 我该怎么做?

UPDATE: since the fiddle was updated : 更新:由于小提琴已更新:

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 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM