mysql query "not in"

Yung Fei

I have a query

SELECT * FROM `photo` p where 4 not in (2,4,5)

from the query it is not show anything because there is 4. but why if we query

SELECT * FROM `photo` p where 4 not in (user_view)

table photo:

photo ID | user_view
1        | 2,3,4,5

it is still show the record. why the code is not running well if we use not in from the database field?

how to make the same function with

SELECT * FROM `photo` p where 4 not in (2,4,5)

I want to show the record only if the photo is haven't see by user. So it will show uniquely by user who don't have an ID in user_view.thanks

kellanburket

If the column user_view is a comma delimited list like it seems to be, you can use the built-in FIND_IN_SET function:

 SELECT * FROM `photo` p where FIND_IN_SET(4, `user_view`) != 0

This will check if the input '4' exists as one of the items in the user_view column and return the index number if found and 0 if not.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related