我有两张桌子:
COUNTRY
-------------
id
name
NEIGHBOUR
-------------
id
id_country1
id_country2
id_country1
和id_country2
是表COUNTRY
中与彼此相关的国家/地区的ID。
如何制作一个精选语句,以便获取与某个特定国家/地区相邻的所有国家/地区的名称?
答案 0 :(得分:1)
SELECT
COUNTRY.name AS name
FROM
NEIGHBOUR
INNER JOIN COUNTRY ON
NEIGHBOUR.id_country1=COUNTRY.id
OR NEIGHBOUR.id_country2=COUNTRY.id
WHERE
(NEIGHBOUR.id_country1=<your requested id>
OR NEIGHBOUR.id_country2=<your requested id>)
AND COUNTRY.id<><your requested id>