Jump to content

Why does not this query work?


Rommeo

Recommended Posts

I m trying to get the photos that are not in the list..

and my query is this that is not working ;

 

SELECT *

FROM photos

WHERE photoname NOT IN (

"one.jpg, two.jpg"

)

ORDER BY visited ASC

LIMIT 0 , 10

 

query gives me the 10 photos including one.jpg and two.jpg

 

but weirdly when there is just one photo between the "IN" tags, it works, like;

 

SELECT *

FROM photos

WHERE photoname NOT IN (

"one.jpg"

)

ORDER BY visited ASC

LIMIT 0 , 10

 

What am I missing here?

any other keyword do I need to use here?

 

PS : list is comma seperated like one.jpg,two.jpg,three.jpg

Link to comment
https://forums.phpfreaks.com/topic/255939-why-does-not-this-query-work/
Share on other sites

each value that you are comparing against the specified field should be separated by a comma.

 

SELECT *
FROM photos
WHERE photoname NOT IN (
"one.jpg, two.jpg"
)
ORDER BY visited ASC
LIMIT 0 , 10

 

this will check to make sure that the field value is not equal to the literal string "one.jpg,two.jpg".

this is the correct query.

 

SELECT *
FROM photos
WHERE photoname NOT IN (
"one.jpg", "two.jpg"
)
ORDER BY visited ASC
LIMIT 0 , 10

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.