2016-04-05 65 views
-3

我通常通過看例子和反向工作來學習。基本內連接 - 瞭解

有人可以幫助我寫出這個查詢:

https://www.sqlteaching.com/#!multiple_joins

這是我寫的,我不知道我做錯了:

SELECT character.name, actor.name 
FROM character 
INNER JOIN character_tv_show 
ON character.id = character_tv_show.character_id 
INNER JOIN character_actor 
ON actor.id = character_actor.actor_id; 
+0

想通了: SELECT character.name,actor.name FROM字符 INNER JOIN character_actor ON character.id = character_actor.character_id INNER JOIN演員 ON character_actor.actor_id = actor.id; – Sam

回答

1

你引用actor表中的選擇列表和第二個內部聯接中,但絕不會在查詢中包含該表。

+0

那麼爲什麼不這項工作: SELECT character.name,actor.name 從字符 INNER JOIN character_tv_show ON character.id = character_tv_show.character_id INNER JOIN演員 ON actor.id = character_actor.actor_id; – Sam

+0

原因相同,但使用不同的表格。現在,您正在引用「character_actor」表,而不將其包含在查詢中。 – RJM

+0

明白了SELECT character.name,actor.name 從字符 INNER JOIN character_actor ON character.id = character_actor.character_id INNER JOIN演員 ON character_actor.actor_id = actor.id!; – Sam