我已經工作了這2天,我不能例如批准,拒絕和待3個不同的狀態結合我的表值表的所有值..顯示,即使沒有在SQL
在此查詢它只顯示所有已批准的
Select * from
productdesignapproval a,
productinformation b,
department c,
subdivision e,
class f,
subclass g,
productseason h,
year i,
productstylecode j,
productgenericnumber k,
users l
WHERE
a.productinformationID = b.productinformationID AND
b.departmentID = c.departmentID AND
b.subdivisionID = e.subdivisionID AND
b.classID = f.classID AND
b.subclassID = g.subclassID AND
b.productseasonID = h.productseasonID AND
b.yearID = i.yearID AND
a.productinformationID = j.productinformationID AND
a.productinformationID = k.productinformationID AND
l.userID = a.designerID AND a.approvalstatus = 'Approved'
如果我改變了a.approvalstatus待定狀態沒有將出現
數據庫是這樣的,如果設計被批准有特定 productstylecodeĴ值,產品genericnumber K,如果不是,這是我的查詢
Select * from
productdesignapproval a,
productinformation b,
department c,
subdivision e,
class f,
subclass g,
productseason h,
year i,
users l
WHERE
a.productinformationID = b.productinformationID AND
b.departmentID = c.departmentID AND
b.subdivisionID = e.subdivisionID AND
b.classID = f.classID AND
b.subclassID = g.subclassID AND
b.productseasonID = h.productseasonID AND
b.yearID = i.yearID AND
l.userID = a.designerID AND
a.approvalstatus != 'Approved'
如果該值掛起/拒絕沒有productstylecode和genericnumber。
問題如何將2個表格合併爲1個表格?所以我可以顯示所有批准的產品樣式代碼和通用編號以及所有待批准和拒絕的產品樣式代碼和通用編號。謝謝!
您可以用'union'但是請注意,它們必須具有相同的列 – Sherlock
[不良習慣踢:使用舊樣式的JOIN(HTTP: //sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08/bad-habits-to-kick-using-old-style-joins.aspx) - 舊式*逗號分隔的表格樣式列表*樣式在ANSI-** 92 ** SQL標準(**超過20年**之前)中被替換爲* proper * ANSI'JOIN'語法,並且不鼓勵使用它 –