2012-12-19 199 views
2
delete a.Employee_LastName, a.Employee_Firstname 
FROM EMPLOYEE a JOIN DEPARTMENT b on a.Department_ID = b.Department_ID 
where b.Department_Name='Sales' 
Group by a.Employee_LastName, a.Employee_Firstname, b.Department_Name 

你能解釋我做錯了什麼嗎? 錯誤(在sql server 2008中):Msg 102,Level 15,State 1,Line 1 ','附近的語法錯誤。SQL查詢刪除

回答

3

刪除是刪除整個行..不排空場(使列名不支持,也沒有分組

所以

DELETE EMPLOYEE 
FROM EMPLOYEE a JOIN DEPARTMENT b ON a.Department_ID = b.Department_ID 
WHERE b.Department_Name = 'Sales' 

如果你想編輯記錄,那麼我們UPDATE

1

「刪除」後面應該是行,而不是單個的列。你應該這樣做:

delete a 
FROM EMPLOYEE a JOIN DEPARTMENT b on a.Department_ID = b.Department_ID 
where b.Department_Name='Sales' 
Group by a.Employee_LastName, a.Employee_Firstname, b.Department_Name 
1

您不能在刪除語句中指定列。它應該是DELETE FROM <tablename>。另外,如果要使用聯接進行刪除,則需要指定要從哪個表中刪除。所以,像這樣:

DELETE FROM a FROM <tablename> a JOIN <othertable> b ON a.<col> = b.<col>

0

我相信你試圖刪除的列是update而不是delete的值。使用update查詢如下:

update a 
    set a.Employee_LastName = null, 
      a.Employee_Firstname = null 
    from EMPLOYEE a INNER JOIN DEPARTMENT b 
    ON a.Department_ID = b.Department_ID 
    where b.Department_Name='Sales' 

該查詢將從Employee_FirstnameEmployee_LastName列中刪除該值(設置爲null)爲所有員工在Sales部門。

0

基本語法 從 刪去條件

從table_name是其中u還可以創建任意子查詢按您的要求。