Answer the question
In order to leave comments, you need to log in
MySQL How to correctly select a row with an occurrence from a database?
I have two fields in my database.
For example:
Content of field 1: 1, 2, 6
Content of field 2: 1, 3, 6
There is an id.
How can I get rows from the database, in field 1 of which id is included, in field 2 it is not included.
LIKE, NOT LIKE is not suitable, because under them you will have to rebuild the base and write ;1;2;3;, instead of 1, 2, 3
Answer the question
In order to leave comments, you need to log in
Something like this has already been How to make a carousel? just convert to hover
SELECT *
FROM `table`
WHERE 1
AND FIND_IN_SET('1', `field`) > 0
AND FIND_IN_SET('2', `field`) = 0
SELECT *
FROM `table`
WHERE (
(`field` LIKE '1,%' OR `field` LIKE '%,1,%' OR `field` LIKE '%,1') AND
(`field` NOT LIKE '2,%' AND `field` NOT LIKE '%,2,%' AND `field` NOT LIKE '%,2')
)
Switch to PostgreSQL which supports array type https://postgrespro.ru/docs/postgrespro/9.6/arrays
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question