mariadb mysql 语法_MySQL/MariaDB 常用SQL语句

MySQL/MariaDB SQL单表个别字段ID查询select * from table where id in (1,3,5,7,9)

MySQL/MariaDB SQL单表个别字段排除查询select * from table where id not in (2,4,6,8)

示例

PHP中MySQL/MariaDB SQL单表个别字段ID查询的应用

MySQL/MariaDB SQL单表个别字段数据删除delete from table where id in (1,3,5,7,9)

MySQL/MariaDB SQL单表个别字段数据排除删除delete from table where id not in (2,4,6,8)

MySQL/MariaDB SQL查询字段中包含指定ID的数据select * from table where find_in_set(8,group);查询group里含有数字8的记录,group是varchar ,数据格式如:"1,12,8,18,5"

MySQL/MariaDB SQL查询字段中不包含指定ID的数据select * from table where !find_in_set(8,group);查询group里含有数字8的记录,group是varchar ,数据格式如:"1,12,8,18,5"

MySQL/MariaDB SQL多表联合查询SELECT * FROM 主表 join 表2 using(关联字段)

SELECT * FROM 主表 join 表2 using(关联字段)  join 表3 using(关联字段)

示例select * from `table` join `table_data` using(`table_id`) join `table_info` using(`table_id`)

等价于

select 字段名 from 表1,表2 … where 表1.字段 = 表2.字段

MySQL/MariaDB SQL查询表是否存在select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='数据库名' and TABLE_NAME='表名' ;

MySQL/MariaDB SQL过滤指定重复字段select *, count(distinct name) from table group by name结果id  name count(distinct name)

1    a      1

2    b      1

3    c      1示例SELECT * FROM `notes` WHERE `account_id`='75' group by `content_id`select *,count(distinct content_id) from content join column using(`column_id`) join account using(`account_id`) join notes using(`content_id`) where content.content_id in (9,25,26) notes.account_id=75 group by content_id ORDER BY `notes_time` DESC limit 0,10

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值