我如何从Mysql Sakila数据库中获取以下结果:所有电影名称和名称的所有演员的列表
我写了以下查询:
select film_id, actor_id
from sakila.film_actor
where film_id IN (
select film_id from sakila.film
)
返回的查询
film_id actor_id
1 1
1 10
1 20
....
2 19
2 85
,但我也想在此结果集中包括电影的名字和演员的名字。
电影标题在电影桌上,演员名字和姓氏为演员桌。
这是表格结构的方式:
Table Columns
actor actor_id, first name, last name
film film_id, title
film_actor actor_id, film_id(foreign keys to film and actor table)
我尝试了以下查询:
select ac.actor_id, ac.first_name, ac.last_name, fm.title from sakila.film_actor as fa inner join sakila.actor ac on fa.actor_id = ac.actor_id inner join sakila.film fm on fa.film_id = fm.film_id;
但是,这是每个演员的所有电影的返回列表,我想要相反。每部电影中的所有演员
I wrote the following query :
select film_id, actor_id
from sakila.film_actor
where film_id IN (
select film_id from sakila.film
)
which returns
film_id actor_id
1 1
1 10
1 20
....
2 19
2 85
But I also want to include the name of the film and the name of the actor in this result set.
The film title is in film table and the actor first and last name is the actor table.
Here is how the tables are structured :
Table Columns
actor actor_id, first name, last name
film film_id, title
film_actor actor_id, film_id(foreign keys to film and actor table)
I tried the following query :
select ac.actor_id, ac.first_name, ac.last_name, fm.title from sakila.film_actor as fa inner join sakila.actor ac on fa.actor_id = ac.actor_id inner join sakila.film fm on fa.film_id = fm.film_id;
But this returns list of all films for every actor and I want the other way round. All actors in each film
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然,您必须使用内部联接
您必须使用模式中的实际字段名称。 (我只是猜测
film_name
,first_name
和last_name
。Use an inner join
You'll have to use the actual field names from your schema, of course. (I just guessed
film_name
,first_name
, andlast_name
.)