G
G
Gumper2019-08-21 16:21:45
PHP
Gumper, 2019-08-21 16:21:45

How to make double condition in SQL query?

When creating a blog site, I ran into a problem.
I can't figure out how to make a double condition in a SQL query,
here's the code:

SELECT * FROM `comics` WHERE `categories_id` = '17' OR `categories_id_2` = '17' OR `categories_id_3` = '17' OR `categories_id_4` = '17' OR `categories_id_5` = '17' OR `categories_id_6` = '17' OR `categories_id_7` = '17' OR `categories_id_8` = '17' AND `categories_id` = '1' OR `categories_id_2` = '1' OR `categories_id_3` = '1' OR `categories_id_4` = '1' OR `categories_id_5` = '1' OR `categories_id_6` = '1' OR `categories_id_7` = '1' OR `categories_id_8` = '1' ORDER BY `id` DESC

Result:
5d5d4497d77d5154431164.png
But the problem is that I only need articles with two categories:
5d5d44de957e2477884887.png
How can this be solved, or should I just cut off the extra ones in PHP?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
oleg_ods, 2019-08-21
@Gumper

Esteem that such the third normal form and that such communications.
You need to put the categories in a separate table and implement a many-to-many relationship. When you do this, your question will disappear by itself)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question