简体   繁体   中英

MySQL find_in_set selecting not working

I'm trying to do the following:

  • Select from current year: Working
  • Select where user_id is in comma seperated list 'users': Works
  • Select where user_id is NOT in comma seperated list 'accepted' OR 'rejected': Not working

But for some reason I don't get the results I want. See my following code:

SELECT   *, MONTH(datetime) AS month
FROM     $table_name
WHERE    YEAR(datetime) = $current_year
AND      find_in_set('%$user_id%', users)
AND NOT  find_in_set('%$user_id%', accepted) OR NOT find_in_set('%$user_id%', rejected)
ORDER BY datetime

Put the NOT clause condition in parenthesis.

WHERE    YEAR(datetime) = $current_year
AND      find_in_set('%$user_id%', users)
AND (    NOT find_in_set('%$user_id%', accepted) 
      OR NOT find_in_set('%$user_id%', rejected) )

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