View Full Version : Help with Update query


mufasa
07-25-2007, 12:33 AM
HI There

I have 2 tables Table1 (T1_ID int, Invoice_no vchar) and Table2(T2_ID int, Invoice vchar, Product vchar).

The problem I have is that my client has records in Table2 Invoice with data from Table1 Column T1_Id and Invoice_no.

What I would like to do is to update Table2 Invoice with only the data from Table1 T1_ID

Table1
T1_ID ______________ Invoice_No
1___________________635
2___________________646
3___________________985

Table2
T2_ID___________Invoice________Product
1______________1______________beans
2______________646____________Bananas
3______________3______________Apples

Guus2005
07-26-2007, 12:55 AM
Not sure what the question is, but here goes:
You want to delete records from table2 when InvoiceNo not in Table1?

Delete * from Table2 where Invoice not in (Select Invoice_No from Table1)

This query removes "beans" and "Apples" from table2

HTH

Ian Mac
07-26-2007, 01:43 AM
I think your example is a little mis-leading as you are using the same numbers for T1_ID and T2_ID. If I have read this correctly this is not the case.

Try:

UPDATE Table1 INNER JOIN Table2 ON Table1.Invoice_No = Table2.Invoice SET Table2.Invoice = [Table1]![T1_ID];