I want to have a relational data between two table with DELETE
query.
I don't know what keyword should I search and such confusing for me to learn relational database.
So in this case, I want to delete one of the user data in the user
table.
So the buy_product
table which contains the user_id
column will also be deleted along with the rows in it.
This is user
table:
user_id | name |
---|---|
1 | John |
2 | Doe |
This is buy_product
table:
id_product | name | user_id |
---|---|---|
1 | Cookies | 2 |
2 | Pizza | 2 |
3 | Burger | 1 |
For example, if I run the DELETE FROM user WHERE user_id = 2
query, the result is:
user_id | name |
---|---|
1 | John |
And buy_product
table with user_id
= 2 also deleted the data that I want without run DELETE FROM buy_product WHERE user_id = 2
query like this:
id_product | name | user_id |
---|---|---|
3 | Burger | 1 |
I think for all understandable answers means a lot to me. Thanks!