(2)sql 学习 : CONCAT ,SQL JOIN,union 与 union all,SELECT INTO

来源:互联网 发布:网络打鱼软件 编辑:程序博客网 时间:2024/06/06 01:40
【6】 :sql 学习:CONCAT

1:CONCAT 可以连接多个字段串


SELECT name ,CONCAT(name,',',age) FROM table

2:用单引号和逗号,拼接一个字段的值 GROUP_CONCAT 与 CONCAT 一块用


select GROUP_CONCAT(CONCAT('\'',name,'\'')) FROM table 


【7】:sql 学习: 不同的 SQL JOIN


INNER JOIN:如果表中有至少一个匹配,则返回行


LEFT JOIN:即使右表中没有匹配,也从左表返回所有的行


RIGHT JOIN:即使左表中没有匹配,也从右表返回所有的行


FULL JOIN:只要其中一个表中存在匹配,则返回行



【8】:sql 学习: union 与 union all


1: union 过滤重复
select * from table  where  name='haha'
union 
select * from table  where  name='hehe'


2: union all 不过滤重复
select * from table  where  name='haha'
union  all
select * from table  where  name='hehe'


【9】:sql 学习:SELECT INTO 

SELECT INTO 语句从一个表复制数据,然后把数据插入到另一个新表中。

1:方式一 前提是 table1 已经创建好了

INSERT INTO table1  SELECT * FROM table;


2:方式二  前提是 table1 不存在

CREATE TABLE table1 SELECT * FROM table 


原创粉丝点击