Write a selection request for the following requirement

This is my table users

:

http://ezinfotec.com/Capture.PNG

I need to select all rows that do not contain 2 except the column. How to write a query for this using php and Mysql.

The result I am expecting for this query only returns only the last row.

Thank.

+3


source to share


3 answers


Don't store the values ​​in comma in your table, this is very bad practice, however you can use FIND_IN_SET



SELECT
  *
FROM 
  users
WHERE 
  NOT FIND_IN_SET('2', except)

      

+3


source


Try the following:



SELECT *
FROM users 
WHERE CONCAT(',', except, ',') NOT LIKE '%,2,%'

      

+1


source


this should work for you

SELECT *
FROM table
WHERE table.except NOT LIKE '%,2%'
OR table.except NOT LIKE '%2,%';

      

0


source







All Articles