我有一张名为order_status
的表格。
+-----------------+-------------+-------------------+
| order_status_id | language_id | name |
+-----------------+-------------+-------------------+
| 2 | 1 | Processing |
| 3 | 1 | Shipped |
| 7 | 1 | Canceled |
| 5 | 1 | Complete |
| 8 | 1 | Denied |
| 9 | 1 | Canceled Reversal |
| 10 | 1 | Failed |
| 11 | 1 | Refunded |
| 12 | 1 | Reversed |
| 13 | 1 | Chargeback |
| 1 | 1 | Pending |
| 16 | 1 | Voided |
| 15 | 1 | Processed |
| 14 | 1 | Expired |
| 17 | 1 | Confirmed |
| 18 | 1 | Cash On Delivery |
+-----------------+-------------+-------------------+
我目前正在处理一个查询,我可以选择多个order_status_id
。
通常你可以像这样选择多行:
SELECT FROM order_status WHERE order_status_id = 1 AND order_status_id = 2
上述命令会选择order_status_id
1
和2
。
但是,我想知道你是否可以这样做:
SELECT FROM order_status WHERE order_status_id = (1,2)
,无需多次重写AND order_status_id = 2
。
尝试这一点,我收到了错误:ERROR 1241 (21000): Operand should contain 1 column(s)
我的问题是 - 如何在不使用WHERE
的情况下多次使用AND
选择多行?
答案 0 :(得分:0)
使用in
的正确方法是
WHERE order_status_id in (1,2)
http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_in