MySQL/MariaDB SQL单表个别字段ID查询
1 | select * from table where id in (1,3,5,7,9) |
MySQL/MariaDB SQL单表个别字段排除查询
1 | select * from table where id not in (2,4,6,8) |
示例
PHP中MySQL/MariaDB SQL单表个别字段ID查询的应用
1<br>
MySQL/MariaDB SQL单表个别字段数据删除
1 | delete from table where id in (1,3,5,7,9) |
MySQL/MariaDB SQL单表个别字段数据排除删除
1 | delete from table where id not in (2,4,6,8) |
MySQL/MariaDB SQL查询字段中包含指定ID的数据
1 | select * from table where find_in_set(8,group); |
查询group里含有数字8的记录,group是varchar ,数据格式如:"1,12,8,18,5"
MySQL/MariaDB SQL查询字段中不包含指定ID的数据
1 | select * from table where !find_in_set(8,group); |
查询group里含有数字8的记录,group是varchar ,数据格式如:"1,12,8,18,5"
MySQL/MariaDB SQL多表联合查询
1 2 | SELECT * FROM 主表 join 表2 using(关联字段) SELECT * FROM 主表 join 表2 using(关联字段) join 表3 using(关联字段) |
示例
1select*from`table`join`table_data` using(`table_id`)join`table_info` using(`table_id`)等价于
select 字段名 from 表1,表2 … where 表1.字段 = 表2.字段
MySQL/MariaDB SQL查询表是否存在
1 | select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='数据库名' and TABLE_NAME='表名' ; |
MySQL/MariaDB SQL过滤指定重复字段
1 | select *, count(distinct name) from table group by name |
结果
1234idnamecount(distinctname)1 a 12 b 13 c 1
示例
1SELECT*FROM`notes`WHERE`account_id`='75'groupby`content_id`
1select*,count(distinctcontent_id)fromcontentjoincolumnusing(`column_id`)joinaccount using(`account_id`)joinnotes using(`content_id`)wherecontent.content_idin(9,25,26) notes.account_id=75groupbycontent_idORDERBY`notes_time`DESClimit 0,10
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
相关文章
mysql 主从表数据量差异比对2020-02-29
mysql匹配两个表的相同字段进行更新2020-02-29
Mysql 批量修改数据库前缀程序代码2015-09-12
Mysql使用Update在原字段内容上追加2015-05-16
access转mysql 注定字段2013-10-09
Access导入MySql的PHP程序2013-09-04
mysql 替换指定字符2013-08-14
Mysql连表匹配更新Update 写法2013-08-13
mysql批量去除重复内容的办法2013-08-12