本文介绍了SQL JOIN使用映射表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有三个表:
COLLECTION
PERSON
PERSON_COLLECTION
其中PERSON_COLLECTION
是映射表id|person_id|collection_id
我现在要选择集合中的所有条目,并按person.name
对其进行排序.
I now want to select all entries in collection and order them by person.name
.
我是否必须先将单独的表与映射表联接,然后再对结果进行联接?
Do I have to join the separate tables with the mapping table first and then do a join again on the results?
推荐答案
SELECT
c.*,
p.Name
FROM
Collection c
JOIN Person_Collection pc ON pc.collection_id = c.id
JOIN Person p ON p.id = pc.person_id
ORDER BY p.Name
这篇关于SQL JOIN使用映射表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!