1

I want to query out the first 20 results if category='art' and there is no value in image field.

Can I write an SQL query like this?

SELECT image,date,category FROM imagecart WHERE category='art' AND image != '' Order By date DESC LIMIT 0,20
1
  • That looks right, but depending on how "no image" is stored in your system, you may need ...AND Image IS NULL ORDER BY... instead. Your questions asks for "no value" but your query is filtering for "image is NOT empty"; which do you need? Commented Mar 29, 2011 at 22:34

1 Answer 1

6

Alternatively:

SELECT image,date,category 
FROM imagecart 
WHERE category='art' 
AND LENGTH(image) = 0 
ORDER BY  date DESC LIMIT 0,20

Modify as you need to check for nulls:

AND (LENGTH(image) = 0 OR image IS NULL)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.