not in

G

Guest

I wanted to write an update query which ID must exists in table A but not
table B

I use following SQL, but it seems Access doe snot let me use "not in" and
"in" at same time.

"UPDATE MYTBALE set MYTBALE.Mydata = 1
WHERE MYTABLE.MYDATA2 not in (SELECT MYDATA2 from TABLEA where MYTABLE.MYID
= TABLEA.MYID) and
MYTABLE.MYDATA2 in (SELECT MYDATA2 from TABLEB where MYTABLE.MYID =
TABLEB.MYID)"

I can not save this query with "in" clause, but it works if I have "not in"
only.

Any information is great appreciated,

Thanks millions in advance,
 
J

John Vinson

"UPDATE MYTBALE set MYTBALE.Mydata = 1
WHERE MYTABLE.MYDATA2 not in (SELECT MYDATA2 from TABLEA where MYTABLE.MYID
= TABLEA.MYID) and
MYTABLE.MYDATA2 in (SELECT MYDATA2 from TABLEB where MYTABLE.MYID =
TABLEB.MYID)"

Try modeling this as an Outer Join instead:

UPDATE
(MYTABLE LEFT JOIN TableA ON TableA.MYDATA2 = MYTABLE.MYDATA2)
INNER JOIN TableB ON TableB.MYDATA2 = MYTABLE.MYDATA2
SET MYTABLE.Mydata = 1
WHERE TableA.Mydate2 IS NULL;


John W. Vinson[MVP]
 
G

Guest

Thanks millions,


John Vinson said:
Try modeling this as an Outer Join instead:

UPDATE
(MYTABLE LEFT JOIN TableA ON TableA.MYDATA2 = MYTABLE.MYDATA2)
INNER JOIN TableB ON TableB.MYDATA2 = MYTABLE.MYDATA2
SET MYTABLE.Mydata = 1
WHERE TableA.Mydate2 IS NULL;


John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

delete Using Join Statement 4
subqueries 3
SQL NOT IN CLAUSE 2
Update/Insert Records If Not Exist 1
Not It Query 2
insert a crosstab in to temp table query 2
Updateable Query?????? 8
One-to-many query 4

Top