Pregunta

I am working on putting a MySQL statement together and am wondering what the problem is with it. Why doesn't this MySQL statement work?

SELECT * 
FROM  `deals` 
WHERE CATEGORY NOT 
IN  'Construction & Repair'
AND (
EXPIRE_DATE >= NOW() 
OR EXPIRE_DATE IS NULL
)
AND LOCATION =  'Melbourne'
AND STATUS =  'Active'
LIMIT 0 , 1000

I get the following error message:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Construction & Repair' AND ( EXPIRE_DATE >= NOW( ) OR EXPIRE_DATE IS NULL ) AND' at line 1

¿Fue útil?

Solución

Put it in brackets

WHERE CATEGORY NOT 
IN  ('Construction & Repair')

Otros consejos

I think your syntax is wrong, you want it to be:

 NOT IN ("item1", "item2")

Use

SELECT * 
FROM  `deals` 
WHERE CATEGORY = 'Construction & Repair'
AND (
EXPIRE_DATE >= NOW() 
OR EXPIRE_DATE IS NULL
)
AND LOCATION =  'Melbourne'
AND STATUS =  'Active'
LIMIT 0 , 1000

anything after IN should be in parentheses.

IN('Construction & Repair')
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top