I have two tables with the following structure (rest of the columns omitted for brevity) :
tblORDERS
+-----------+-------+
|Order_ID | Status|
+-----------+-------+
| 100 | 0 |
| 101 | 0 |
| 102 | 0 |
+-----------+-------+
tblUNITS
+------------+-------+----------+
| Unit_ID | Status| Order_Id |
+------------+-------+----------+
| 1 | 1 | 100 |
| 2 | 1 | 100 |
| 3 | 1 | 100 |
| 4 | 1 | 101 |
| 5 | 1 | 101 |
| 6 | 0 | 101 |
| 7 | 0 | 101 |
+------------+-------+----------+
Order_ID
is a Foreign Key on tblUNITS
. There can be many 'units' inside of one 'order'. I need to create an UPDATE
statement that will check tblUNITS
to see if all units with the same order_id
are in status 1, indicating "complete" . If they are, then I want status
in tblORDERS
to be updated to status 1, indicating "complete".
Can anybody help me out in writing such query?
Best Answer
I think this solution will work.