Delete records in different tables
1
vote
1
answer
121
views
I need to delete the records where UserIndex = 1 and ItemNumber = 5202 in all three tables, all in a single query. I am using SQL 2008 R2.
Table UserInfo1
| UserIndex | Itemnumber | ItemCount |
| -------- | --------------- | ---------- |
| 1 | 5202 | 99 |
| 1 | 1600 | 50 |
| 2 | 155 | 2 |
| 3 | 125 | 60 |
Table UserInfo2
| UserIndex | Itemnumber | ItemCount |
| -------- | --------------- | ---------- |
| 8 | 1265 | 50 |
| 4 | 1899 | 41 |
| 1 | 5202 | 99 |
| 3 | 125 | 60 |
Table UserInfo3
| UserIndex | Itemnumber | ItemCount |
| -------- | --------------- | ---------- |
| 6 | 5205 | 85 |
| 1 | 6666 | 41 |
| 3 | 4455 | 44 |
| 1 | 5202 | 50 |
I'm trying to use this query with two tables, but it doesn't work:
DELETE ItemInfo1, ItemInfo2
FROM ItemInfo1
LEFT JOIN ItemInfo2
ON ItemInfo1.UserIndex = ItemInfo2.UserIndex
WHERE ItemInfo1.UserIndex = 1;
Asked by Ichigo Kurosaki
(23 rep)
Mar 10, 2023, 08:22 PM
Last activity: Mar 11, 2023, 03:09 PM
Last activity: Mar 11, 2023, 03:09 PM