sql(join,group,concat)
2019-03-07 本文已影响0人
avery1
MySQL数据库将多条记录的单个字段合并成一条记录
Join
数据库2张表
app表和appProduct表,一个app对应一个appProduct
app表有4个app,appProduct有3条数据,其中1个app没有关联appProduct。


查询app关联appProduct使用inner join会发现只有3条数据。

是因为appid为4和5的在关联表没数据所以不显示,但是如果想要按照app表显示所有,关联没数据显示空的话就要用到left join

如下为他们的区别
(INNER) JOIN:
Returns records that have matching values in both tables
LEFT (OUTER) JOIN:
Return all records from the left table, and the matched records from the right table
RIGHT (OUTER) JOIN:
Return all records from the right table, and the matched records from the left table

concat
我们想要将app里的product的完整信息显示: frontBootstrap, frontJquery(本应该是appProduct表应该只放appid,在创建个表存product,这里简化)
要将peoduct的displayname和level连起来。用CONCAT

group
在appProduct表里在加数据,app可以对应多个appProdcut


将appid一样的放到一起,group一下会忽略掉一样appid的用GROUP_CONCAT
