You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: basics/Beginner-Guide-to-SQL.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,6 +57,24 @@ UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
57
57
-- Update the table using a subquery to set the value of column1 based on the result of the subquery, where the condition is met
58
58
UPDATE table_name SET column1 = (SELECT expression) WHERE condition;
59
59
60
+
```
61
+
62
+
For example:
63
+
```sql
64
+
-- Update specific records in the table 'employees' to set their 'status' to 'active' where 'department' is 'Sales'
65
+
UPDATE employees SET status ='active'WHERE department ='Sales';
66
+
67
+
-- Update multiple columns in the table 'products' to set 'price' to 10.99 and 'stock' to 100 where 'category' is 'Electronics'
68
+
UPDATE products SET price =10.99, stock =100WHERE category ='Electronics';
69
+
70
+
-- Update the table 'orders' to set the 'total_price' column based on the sum of prices from the 'order_items' table for each order, where 'order_id' matches
71
+
UPDATE orders
72
+
SET total_price = (
73
+
SELECTSUM(price)
74
+
FROM order_items
75
+
WHEREorder_items.order_id=orders.order_id
76
+
)
77
+
WHERE condition;
60
78
```
61
79
## DELETE
62
80
The `DELETE` statement is used to delete existing records from a table.
0 commit comments