SQL 语句到 Return 来自两个表的结果
SQL Statement to Return Results from Two Tables
我尝试搜索这个问题,但我认为我的措辞不正确。
我有两个 table,一个用于案例,一个用于订购的硬件,订购的硬件 table 存储下订单的人、订购的日期等,但我只想要一列这个 table 是硬件订购的,是或否。
我现在的想法是,我将在案例 table 中查询我想要的所有字段,然后我想从订购的硬件 table 添加一列。
我尝试了内部联接,但没有返回任何内容。
SELECT Cases.CreatedBy
, Cases.CreatedByEmail
, Cases.CreatedByID
, Cases.CaseID
, HardwarePart.Ordered
FROM Cases
INNER JOIN HardwarePart
ON Cases.RecID = HardwarePart.RecID
WHERE
Cases.CreatedDateTime BETWEEN '2019-01-01 00:00:00.000' AND '2019-03-13 23:59:59.999'
我认为你的问题在于两个 table 之间的关系 INNER JOIN HardwarePart ON Cases.RecID = HardwarePart.RecID
是 Cases.RecID
table 中的主键 Cases
而 HardwarePart.RecID
是 HardwarePart
中与 Cases
连接的外键?
我尝试搜索这个问题,但我认为我的措辞不正确。
我有两个 table,一个用于案例,一个用于订购的硬件,订购的硬件 table 存储下订单的人、订购的日期等,但我只想要一列这个 table 是硬件订购的,是或否。
我现在的想法是,我将在案例 table 中查询我想要的所有字段,然后我想从订购的硬件 table 添加一列。
我尝试了内部联接,但没有返回任何内容。
SELECT Cases.CreatedBy
, Cases.CreatedByEmail
, Cases.CreatedByID
, Cases.CaseID
, HardwarePart.Ordered
FROM Cases
INNER JOIN HardwarePart
ON Cases.RecID = HardwarePart.RecID
WHERE
Cases.CreatedDateTime BETWEEN '2019-01-01 00:00:00.000' AND '2019-03-13 23:59:59.999'
我认为你的问题在于两个 table 之间的关系 INNER JOIN HardwarePart ON Cases.RecID = HardwarePart.RecID
是 Cases.RecID
table 中的主键 Cases
而 HardwarePart.RecID
是 HardwarePart
中与 Cases
连接的外键?