A数据表中多个字段对应B数据表的ID,
现在要把B表的其他字段一起查询出来
一、数据表:
1、SPEED_DETECTION_ROAD
它的 START_POINT_ID 和 END_POINT_ID字段对应下面表的ID,
2、SECTION_INFO:
二、SQL语句:
SELECT section1.SECTION_NAME AS sectionStart,
section2.SECTION_NAME AS sectionEND FROM [ZLITS_HCVS].[dbo].[SPEED_DETECTION_ROAD] AS road inner join [ZLITS_HCVS].[dbo].[SECTION_INFO] AS section1
on road.START_POINT_ID = section1.SECTION_ID inner join [ZLITS_HCVS].[dbo].[SECTION_INFO] AS section2
on road.END_POINT_ID = section2.SECTION_ID
思路:
SPEED_DETECTION_ROAD表有两个字段是SECTION_INFO表的ID,
因此,Inner Join 数据表SECTION_INFO两次
三、查询结果