Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSSql (Compact) DELETE-Query with JOIN

I have this query. I want to delete all entities from AgentsResultLinks-Table, that don't have a link to a entity in Results-Table. I want a solution with one single query. I got an error caused by '*'.

DELETE AgentResultLinks.*
FROM AgentResultLinks LEFT JOIN Results 
ON AgentResultLinks.ResultID = Results.ID
WHERE Results.ID IS NULL

Can someone help me to convert this query in a vaid mssql query for compact database ? The Performance is very important.

like image 340
Gepro Avatar asked Sep 21 '12 07:09

Gepro


1 Answers

Just remove .* from AgentResultLinks.*

DELETE Agent
FROM AgentResultLinks Agent 
LEFT JOIN Results R
       ON Agent.ResultID = R.ID
WHERE R.ID IS NULL;

See DELETE syntax: DELETE (Transact-SQL)

See SQLFiddle Example

like image 124
Himanshu Jansari Avatar answered Sep 20 '22 02:09

Himanshu Jansari