2013-07-03 144 views
0

我试着从具有相同的列2个表中选择,但两个表有一个内部联接 -SQL UNION INNER JOIN

select e.ID, 
    c.FullName, 
    car.VIN, 
    car.Registration, 
    e.Telephone, 
    e.Mobile, 
    e.Email, 
    e.EstimateTotal, 
    e.LastUpdated, 
    e.LastUpdateBy from (select id from Estimates UNION ALL select id from PrivateEstimates) e 

inner join Customers c on c.ID = e.CustomerID 
inner join Cars car on car.ID = e.CarID 
where e.Status = 0 

麻烦的是,它无法找到e.CustomerID,E。内部连接上的CarID或e.Status?有任何想法吗?

回答

3

您的子作业(select id from Estimates UNION ALL select id from PrivateEstimates)仅返回单个id列。如果您要使用JOIN陈述中的那些字段,请在子查询中包含必要的字段