首頁 >後端開發 >php教程 >SELECT时候,如何跳过带有空值字段的数据项?

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

WBOY
WBOY原創
2016-06-06 20:51:181604瀏覽

以下是我的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"
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn