Arielsp
Arielsp

Reputation: 115

Error in SQL query expression

I´m trying to run the following SQL code on access 2010, but it returns syntax error in query expression. Any ideas what could be causing it?

Thanks in advance.

DELETE FROM Trn_done 
WHERE (Trn_done.training = 
SELECT Training  
FROM Trainings 
WHERE (Trainings.Area = '" & Area & "'))

Upvotes: 1

Views: 87

Answers (2)

Bill Gregg
Bill Gregg

Reputation: 7147

You shouldn't EQUAL a select statement, lest multiple rows in your select cause your code to break. Try this instead:

DELETE td 
from Trn_done td
inner join Trainings t 
on td.training = t.training
WHERE t.Area = '" & Area & "'

Upvotes: 3

vbdv
vbdv

Reputation: 54

The bracket should be before the nested SQL as mentioned below

DELETE FROM Trn_done
WHERE Trn_done.training IN (
    SELECT Training 
    FROM Trainings
    WHERE (Trainings.Area = '" & Area & "')
)

Upvotes: 3

Related Questions