Mysql
主页 > 数据库 > Mysql >

mysql设置某字段不能重复问题

2022-08-24 | 佚名 | 点击:

mysql设置某字段不能重复

1

alter table novel.novelsort add unique(name);

novel是数据库 novelsort是表名 name是字段名

mysql查询某个字段不重复的所有记录

1

2

3

select a.id,a.ip,a.creationTime from myTable a right join (

select max(id) id from myTable group by ip) b on b.id = a.id

where a.id is not null

或者

1

2

3

select a.* from myTable a right join (

select max(id) id from myTable group by ip) b on b.id = a.id

where a.id is not null

表名为myTable

原文链接:https://blog.csdn.net/rj2017211811/article/details/88755932
相关文章
最新更新