2013-07-03 183 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陳述中的那些字段,請在子查詢中包含必要的字段