如果value为空,则查询mysql

时间:2011-03-29 22:32:07

标签: mysql

如果category='art' image并且SELECT image,date,category FROM imagecart WHERE category='art' AND image != '' Order By date DESC LIMIT 0,20 字段中没有值,我想查询前20个结果。

我可以写这样的SQL查询吗?

{{1}}

1 个答案:

答案 0 :(得分:6)

可替换地:

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

修改,因为您需要检查空值:

AND (LENGTH(image) = 0 OR image IS NULL)