首页 > 数据库技术 > 详细

SQL语句-查询MySQL数据库中存在满足某个条件的数据

时间:2020-05-21 12:21:19      阅读:263      评论:0      收藏:0      [点我收藏+]

一、查询MySQL数据库中存在满足某个条件的数据

select ifnull((select 1 from table_name where ip = #{ip} limit 1), 0)

其中ifnull(v1,v2),如果v1为null则返回v2,否则返回v1
select 1 中的1代表常量,效率比 select * 高
limit 1 相当于 limit (0,1),即从第0条开始取1条数据

二、查询某个字段不为空

select * from table_name where name is not null order by id desc

字段名+is not null,即判断该字段不为空
order by id,根据id进行排列
desc,降序排列

SQL语句-查询MySQL数据库中存在满足某个条件的数据

原文:https://www.cnblogs.com/antguo/p/12928884.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!