从INNER JOIN中的一个表中获取唯一行

时间:2016-08-05 13:50:07

标签: mysql

是否有任何解决方法可以获取zc_orders表中的唯一行?我只需要来自zc_zc_orders_status_history的注释字段(具有重复的行)。这是我的问题:

SELECT
zc_orders.orders_id,
zc_orders_status_history.comments,
zc_orders_status_history.orders_status_id,
zc_customers.customers_email_address,
zc_customers.customers_telephone,
zc_customers.customers_firstname,
zc_customers.customers_lastname,
zc_orders_status_history.date_added,
zc_orders.date_purchased
FROM
zc_customers
INNER JOIN zc_orders ON zc_orders.customers_id = zc_customers.customers_id
INNER JOIN zc_orders_status_history ON 
zc_orders_status_history.orders_id = zc_orders.orders_id
where zc_orders_status_history.orders_status_id = 8
ORDER BY zc_orders_status_history.date_added DESC

1 个答案:

答案 0 :(得分:0)

SELECT DISTINCT
zc_orders_status_history.comments,
FROM
zc_customers
INNER JOIN zc_orders ON zc_orders.customers_id = zc_customers.customers_id
INNER JOIN zc_orders_status_history ON 
zc_orders_status_history.orders_id = zc_orders.orders_id
where zc_orders_status_history.orders_status_id = 8
ORDER BY zc_orders_status_history.date_added DESC