SQL Syntax (1)
SQL Syntax (1)
DDL Commands
DML Commands
1. Inserting Records into a Table: INSERT INTO <table_name> VALUES(<values_list1>), (<values_list2>);
2. Updating Records in a Table: UPDATE <table_name> SET <col_name> = <new_value> WHERE <condition>;
3. Deleting Records from a Table: DELETE FROM <table_name> WHERE <condition>;
DQL Commands
1. Display all Records from a Table: SELECT * FROM <table_name>;
2. Display only certain Columns from a Table: SELECT <col_name1><col_name2> FROM <table_name>;
3. Display Text with Records of the Table: SELECT <col_name1> <text> <col_name2> FROM <table_name>;
4. Display added/subtracted integer with Records of a Table: SELECT <col_name1><col_name2_type=int>+<number> FROM <table_name>;
5. Display the Records of a Table with an Alias Name: SELECT <col_name1> AS <alias_name> FROM <table_name>;
6. Display the Records of a Table satisfying a Condition: SELECT * FROM <table_name> WHERE <condition> <conjunctive_operator> <condition>;
7. Display Unique Records from a Table: SELECT DISTINCT <col_name> FROM <table_name>;
8. Display the Records of a Table Between a certain range: SELECT * FROM <table_name> WHERE <col_name> BETWEEN <value1> AND <value2>;
9. Display the Records of a Table with a certain value: SELECT * FROM <table_name> WHERE <col_name> IN (<value1>,<value2>,<value3>);
10. Display the Records of a Table showing a Pattern: SELECT * FROM <table_name> WHERE <col_name> LIKE <value_and_wildcard>;
11. Display the Records of a Table in the Appending Order of a Column: SELECT * FROM <table_name> ORDER BY <col_name> ASC;
12. Display the Records of a Table in the Descending Order of a Column: SELECT * FROM <table_name> ORDER BY <col_name> DESC;
13. Display the Maximum Value of a Column in a Table: SELECT MAX(<col_name>) FROM <table_name>;
14. Display the Minimum Value of a Column in a Table: SELECT MIN(<col_name>) FROM <table_name>;
15. Display the Sum of Values of a Column in a Table: SELECT SUM(<col_name>) FROM <table_name>;
16. Display the Average Value of a Column in a Table: SELECT AVG(<col_name>) FROM <table_name>;
17. Display the Number of Records in a Table: SELECT COUNT(*) FROM <table_name>;
18. Display the Number of Values in a Column of a Table: SELECT COUNT(<col_name>) FROM <table_name>;
19. Display the Number of Unique Values in a Column of a Table: SELECT COUNT(DISTINCT <col_name>) FROM <table_name>;
20. Display the Records of a Table Group-wise: SELECT <col_name1><col_name2> FROM <table_name> GROUP <col_name1> HAVING <aggregate_functions>;
21. Cartesian Product of two Tables: SELECT <x>.<col_name1>, <y>.<col_name2> FROM <table_name1> <x>, <table_name2> <y>,
➔ WHERE <x>.<primary_key > = <y>.<foreign_key >;
Others
wildcard: [%, _]