Rodolfo Awenydd Luna Bernal Rodolfo Awenydd Luna Bernal - 6 months ago 19
SQL Question

Right syntax for WHERE IN in Joomla Jdatabase

I have this query

SELECT *
FROM #__k2_items
WHERE catid IN ('4,10,11,12,13,14,15,16,17,18,19,20,21,22')
AND published='1'


But it's not working, it is just retrieving items from catid 4.

Thanks in advance.

Answer

You want

SELECT * 
FROM #__k2_items 
WHERE catid IN (4,10,11,12,13,14,15,16,17,18,19,20,21,22)
  AND published=1

or

SELECT * 
FROM #__k2_items 
WHERE catid IN ('4','10','11','12','13','14','15','16','17','18','19','20','21','22')
  AND published='1'
Comments