[英]Select Two different values in the same column in MySQL
SELECT *
FROM `products`
WHERE (
`category` = 'a'
AND `category` = 'b'
)
products
---
id sku category
-------------------------
1 34343 a
2 32523 d
3 23234 b
4 23433 b
5 23442 c
I want to return A and B 我想要回归A和B.
SELECT *
FROM `products`
WHERE (
`category` = 'a'
OR `category` = 'b'
)
OR 要么
SELECT *
FROM `products`
WHERE
`category` IN ('a', 'b')
You can use IN clause to replace many OR conditions. 您可以使用IN子句替换许多OR条件。 IN simply checks whether a value is within a set of values. IN只是检查值是否在一组值内。
You have to use the OR operator because with AND you select where category is A and B but you have to select where category are A or B 您必须使用OR运算符,因为使用AND选择类别为A和B的位置,但您必须选择A或B类别的位置
SELECT *
FROM `products`
WHERE (
`category` = 'a' OR `category` = 'b'
)
SELECT *
FROM `products`
WHERE `category` in('a','b')
SELECT * FROM products
WHERE category
('a','b')
you can do like this: 你可以这样做:
SELECT c1 FROM table WHERE c2 IN (1,2,3,4) GROUP BY c1 HAVING COUNT(c2)=4; SELECT c1 FROM table WHERE c2 IN(1,2,3,4)GROUP BY c1 HAVING COUNT(c2)= 4;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.