ThinkPHP5.1 查询空或非空字段数据
ThinkPHP5.1
查询归属人是空的条件,并按照id的降序排列一页显示15条,用whereNull
db('table')->whereNull('belong')->order('id','desc')->paginate(15);
查询归属人不为空的条件,并按照id的降序排列一页显示15条,whereNotNull
db('table')->whereNotNull('belong')->order('id','desc')->paginate(15);
查询归属人是空的条件,并按照id的降序排列一页显示15条,用not null
db('alldata')->where('belong','not null')->order('id','desc')->paginate(15);
查询归属人是空的条件,并按照id的降序排列一页显示15条,用null
db('alldata')->where('belong','null')->order('id','desc')->paginate(15);
此两种方法适用tp5以前
$where['belong'] = array('exp',' is NULL');
$where['belong'] = array('exp',' not null');
ThinkPHP5.1
MySQL查找空字段或不为空的字段
MySQL查询空字段数据:
select * from table where id = '';
select * from table where isnull(age);
MySQL查询不为空字段的数据(非空数据):
select * from table where age <> '';
select * from table where age != '';