سؤال

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) )
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top