简体   繁体   中英

Multiple AND conditions in a mysql query

+------------+--------------------+----------+-------------+
| id_product | name               | id_brand | id_category |
+------------+--------------------+----------+-------------+
|          1 | Nokia E55          |      120 |           1 |
|          2 | Nokia E75 (Red)    |      101 |           1 |
|          3 | Nokia N86          |      105 |           2 |
|          4 | Nokia 6700 Classic |      110 |           2 |
|          5 | Nokia 6260 Slide   |      120 |           1 |
+------------+--------------------+----------+-------------+

What I want to do is, I have the following data

id_category = 1,2
id_brand = 110,105

Now I want the following products

Nokia 6700 Classic
Nokia N86

only

because there is no brand (110,105) in id_category 1.......

我相信您正在寻找:

WHERE id_category IN (1,2) AND id_brand IN (110,105)

尝试这个:

WHERE id_category in (1,2) and  id_brand in (110,105)

尝试这个

select name from tbl_name where id_category in (1,2) and id_brand in (110,105);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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