我必须从三个表中选择值。第一个表格为sale_project_detail
,第二个表格为design_project_detail
,第三个表格为design_designer
。
sale_project_detail
架构:
Id int,
Name nvarchar(50),
ShortDescription nvarchar(max)
design_project_assignment
架构:
Id int,
DId int (It is foreign key of design_designer table),
SPId int (It is foreign key of sale_project_detail table),
AssignDateTime datetime,
DueDate date,
Status varchar(10)
design_designer
架构:
Id int,
Name nvarchar(15)
现在,我必须从sale_project_detail
where assign_project_detail.SPId <> sale_project_detail.Id,
和
Select design_designer(Name)
from design_designer
where design_designer.Id = assign_project_detail.DId
我正在尝试下面的代码,但它返回了错误的结果。
我的代码:
SELECT
sale_project_detail.*,
design_project_assignment.*,
design_designer.Name
FROM
sale_project_detail,
design_project_assignment,
design_designer
WHERE
NOT EXISTS(SELECT NULL
FROM design_project_assignment
LEFT JOIN design_designer ON design_designer.Id = design_project_assignment.DId
WHERE sale_project_detail.Id = design_project_assignment.SPId)
提前致谢。
答案 0 :(得分:0)
试试这个
SELECT
*
FROM
sale_project_detail as spd
inner join design_project_assignment dpa on dpa.spid <> spd.id
inner join design_designer dd on dd.id = dpa.did;