Mysql查询不显示值不相等的行

时间:2013-03-08 11:04:23

标签: mysql select

我的mysql查询有一些小问题。我想只显示订单状态不同于6的行。但id_order有多个雕像,意思是:

id_order = 8421
**has two statuses:**
id_order_state=8 and
id_order_state = 6.

这是我的表格示例:link

我尝试过:

SELECT * FROM order_history WHERE id_order_state != 6 (but here I need more code that I can't handle)

感谢您的帮助

编辑:订单8421,8422不应显示在结果

3 个答案:

答案 0 :(得分:1)

试试这个

> SELECT * FROM order_history WHERE id_order_state <> 6

> SELECT * FROM order_history WHERE id_order_state NOT IN ( 6)

答案 1 :(得分:1)

尝试:

SELECT i.* FROM order_history i
left join order_history e 
       on i.id_order = e.id_order and e.id_order_state = 6
WHERE  e.id_order_hitory is null

答案 2 :(得分:0)

就像这样?

SELECT * 
FROM order_history 
WHERE id_order NOT IN 
(SELECT id_order FROM order_history WHERE id_order_state = 6);