MySQL入门 互动版

多表查询


查询多个表,from子句列出表名,并用逗号分隔,因为查询需要从他们两个拉出信息

基本语法:

select t1.name,t2.name from tb_name1 as t1,tb_name2 as t2 where t1.name=t2.name;

上述代码表示,从t1和t2中取出两张表name相同的值。as表示为这个表取别名。

实例如下:

 select t1.name as t1name,t1.age as t1age,t2.name as t2name,t2.age as t2age
 from test01_01 as t1,test01_03 as t2 where t1.name=t2.name;
选用test01数据库,查询出test01_01表中与test01_02表中地址相同的数据