Domanda

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
È stato utile?

Soluzione

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) )
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top