@@ -15,55 +15,60 @@ The most fundamental operations in SQL are known as CRUD, which stands for **Cre
1515The ` SELECT ` statement is used to select data from a database. The data returned is stored in a result table.
1616
1717``` sql
18- -- Select all columns from a table
19- SELECT * FROM table_name ;
18+ -- Select all columns from a table named 'employees'
19+ SELECT * FROM employees ;
2020
21- -- Select specific columns from a table
22- SELECT column1, column2 FROM table_name;
21+ -- Select specific columns (employee ID and name) from the 'employees' table
22+ SELECT employee_id, employee_name FROM employees;
23+ 24+ -- Select employees from the 'employees' table who are in the 'Sales' department
25+ SELECT * FROM employees WHERE department = ' Sales' ;
2326
24- -- Select with a condition
25- SELECT * FROM table_name WHERE condition;
2627```
2728
2829## INSERT
2930The ` INSERT INTO ` statement is used to insert new records into a table.
3031
3132``` sql
32- -- Insert into specific columns
33- INSERT INTO table_name (column1, column2 ) VALUES (value1, value2 );
33+ -- Insert specific data into columns of a table named 'customers'
34+ INSERT INTO customers (customer_name, email ) VALUES (' John Doe ' , ' john@example.com ' );
3435
35- -- Insert into all columns
36- INSERT INTO table_name VALUES (value1, value2, value3, ... );
36+ -- Insert data into all columns of the 'customers' table
37+ INSERT INTO customers VALUES (1 , ' Jane Smith ' , ' jane@example.com ' , ' New York ' );
3738
38- -- Insert multiple rows
39- INSERT INTO table_name (column1, column2)
40- VALUES (value1, value2), (value3, value4), (value5, value6);
39+ -- Insert multiple rows into a table named 'orders'
40+ INSERT INTO orders (order_id, customer_id, order_date)
41+ VALUES
42+ (101 , 1 , ' 2024年04月14日' ),
43+ (102 , 2 , ' 2024年04月15日' ),
44+ (103 , 3 , ' 2024年04月16日' );
4145
4246```
4347
4448## UPDATE
4549The ` UPDATE ` statement is used to modify existing records in a table.
4650``` sql
47- -- Update specific records
51+ -- Update specific records in the table with new values for column1 where the condition is met
4852UPDATE table_name SET column1 = value1 WHERE condition;
4953
50- -- Update multiple columns
54+ -- Update multiple columns in the table with new values for column1 and column2 where the condition is met
5155UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
5256
53- -- Update using a subquery
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
5458UPDATE table_name SET column1 = (SELECT expression) WHERE condition;
59+ 5560```
5661## DELETE
5762The ` DELETE ` statement is used to delete existing records from a table.
5863``` sql
59- -- Delete specific records
64+ -- Delete specific records from the table where the condition is met
6065DELETE FROM table_name WHERE condition;
6166
62- -- Delete all records
67+ -- Delete all records from the table
6368DELETE FROM table_name;
6469
65- -- Delete using a subquery
66- DELETE FROM table_name WHERE column IN (SELECT column FROM another_table WHERE condition);
70+ -- Delete records from the table using a subquery to match values in a column with values from another table based on certain conditions
71+ DELETE FROM table_name WHERE column_name IN (SELECT column_name FROM another_table WHERE condition);
6772
6873```
6974## Conclusion
0 commit comments