Mysql 笔记

mysql删除重复:

1 select * from data_content_357 where id not in (select max(id) from data_content_357 group by Rating);
2 
3 解析:
4 max(id):把ID最大值筛选出来,就等于选出了1条不重复记录
5 group by :按哪个字段分组,就会选择出哪个字段的不重复记录
6 not in:为什么是not in呢?我准备把它筛选出来再删掉的!删掉是这样:
7 delete * from data_content_357 where id not in (select max(id) from data_content_357 group by Rating);

 

Mysql合并多个表:

 1 2.access把一个新表插入一个旧表:
 2 UPDATE 表2 INNER JOIN 表1 ON 表2.ID = 表1.ID 
 3 SET 表1.我叫 = [表2]![我叫] WHERE ((([表2]![ID])=[表1]![ID]));
 4 
 5 3.怎样将结构完全一样的两个表的内容合并到一个表中,SQL语句
 6 select * 
 7 into 新表名 
 8 from (select * from T1 union all select * from T2) 
 9 
10 这个语句可以实现将合并的数据追加到一个新表中。 
11 
12 不合并重复数据 
13 select * from T1 union all select * from T2 
14 
15 合并重复数据 
16 select * from T1 union select * from T2        
17 两个表,表1 表2 
18 如果要将 表1的数据并入表2用以下语句即可 
19 
20 insert into 表2(字段1,字段2) select 字段1,字段2 from b1 
21 
22 insert into Content(标题,产品,mainmarkets,colour,size,style,简介,Price,Capacity,缩略图,图1,图2,图3) select 标题,产品,mainmarkets,colour,size,style,简介,Price,Capacity,缩略图,图1,图2,图3 from Content1;
23 
24 注意,必须把字段名全部写清楚,而且不允许把自动编号进去写进去,要合并自动编号字段必须重写一个算法一条一条记录地加进去
25 1 insert into b1 select * from b2 
26 2 select * into newtable from (select * from b1 union all select * from b2)

 

Mysql替换

1 UPDATE `table1` SET `title` = replace(title, 'abc', '123') WHERE `typeid` =18;

 

你可能感兴趣的:(Mysql 笔记)