Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a38bbec

Browse files
authored
Update Beginner-Guide-to-SQL.md
1 parent 042bb7f commit a38bbec

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎basics/Beginner-Guide-to-SQL.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
5757
-- Update the table using a subquery to set the value of column1 based on the result of the subquery, where the condition is met
5858
UPDATE table_name SET column1 = (SELECT expression) WHERE condition;
5959

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 = 100 WHERE 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+
SELECT SUM(price)
74+
FROM order_items
75+
WHERE order_items.order_id = orders.order_id
76+
)
77+
WHERE condition;
6078
```
6179
## DELETE
6280
The `DELETE` statement is used to delete existing records from a table.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /