如何通过查询语句来选择多个表?

时间:2017-07-15 23:06:07

标签: mysql select join

mysql中有三个表。

表1:

 create table a1{
 no int primary key AUTO_INCREMENT,
 member_no int,
 channel varchar(50)
 };

表2:

create table a2(
no int primary key AUTO_INCREMENT,
member_no int, 
title varchar(100) not null,
description varchar(400),
video_name varchar(100)
);

表3:

 create table a3(
 no int primary key AUTO_INCREMENT,
 member_no int, 
 video_name varchar(100)
);

我想选择满足相同条件的a1.channel。 如何编写查询语句?

这是我到目前为止所做的:

select * from a2 a join a3 b on a.video_name=b.video_name and b.member_no=#          
     {member_no};

1 个答案:

答案 0 :(得分:0)

钝的表名没有帮助(a1,a2,a3)有钝的别名(a,b)不能让人理解,但也许这会有所帮助。

select * 
from a2 a 
join a3 b on on a.member_no = b.member_no and a.video_name = b.video_name 
join a1 c on a.member_no = c.member_no
where a.member_no= {member_no}
;