欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

SELECT时候,如何跳过带有空值字段的数据项?

程序员文章站 2022-06-03 09:25:50
...
以下是我的php代码:,
$sql = "SELECT author,tags,subject,tid,authorid,dateline,fid FROM threads ORDER BY dateline DESC LIMIT 10"

如果tags是空值,则跳过,该怎么改呢?

回复内容:

以下是我的php代码:,

$sql = "SELECT author,tags,subject,tid,authorid,dateline,fid FROM threads ORDER BY dateline DESC LIMIT 10"

如果tags是空值,则跳过,该怎么改呢?

如果空值是:NULL
则:

$sql = "SELECT author,tags,subject,tid,authorid,dateline,fid FROM threads WHERE tags IS NOT NULL ORDER BY dateline DESC LIMIT 10"

如果空值是:''

$sql = "SELECT author,tags,subject,tid,authorid,dateline,fid FROM threads WHERE tags !='' ORDER BY dateline DESC LIMIT 10"
相关标签: php mysql