mysql查询高级用法

联合查询
select   a.* , b.adress ,  b.name   from   a , b   where   a.sbNo = b.cdid  order by   a.sbNo , a.STime
select a.a_id, a.a_name, b.b_name from A a, B a where a.b_id = b.b_id //联合查询 
insert into table1 (xx,yy,zz) select xx,yy,zz from table2;
select axx as id, att as name from tb1 union select bxx as id, btt as name from tb2 整合有关联的两个数据表里的字段 update TableA AS ta, TableB AS tb SET ta.field1 = tb.field1 WHERE ta.id = tb.ta_id //经典案例 (新用户)通过表A获取的记录集,如下: 1 2012-11-1 3 2012-11-2 8 2012-11-5 (老用户)通过表B获取的记录集,如下: 5 2012-11-1 3 2012-11-2 我想将这两个结果集合并为一个结果集。显示的结果如下: 日期 新用户 老用户 2012-11-1 1 5 2012-11-2 3 3 2012-11-5 8 0 select a.col2, a.id, ifnull(b.id, 0) from newuser a left join olduser b on a.col2=b.col2; http://www.cnblogs.com/JuneZhang/archive/2010/08/26/1809306.html

 

你可能感兴趣的:(mysql查询高级用法)