一个表中多个字段对应另一个表的ID(SQL查询)

A数据表中多个字段对应B数据表的ID,

现在要把B表的其他字段一起查询出来

一、数据表:

1、SPEED_DETECTION_ROAD

一个表中多个字段对应另一个表的ID(SQL查询)

它的 START_POINT_ID 和 END_POINT_ID字段对应下面表的ID,

2、SECTION_INFO:

一个表中多个字段对应另一个表的ID(SQL查询)

二、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两次

三、查询结果

一个表中多个字段对应另一个表的ID(SQL查询)

上一篇:(Pre sell) ZOPO ZP998 (C2 II) 5.5 inch smart phone True Octa Core MTK6592 1920X1080 FHD screen 401 ppi 2GB/32GB 14.0Mp camera-in Mobile Phones from Electronics on Aliexpress.com


下一篇:C#错误:The Controls collection cannot be modified