Basic SQL Clauses, Keywords & Operators
1. CONCAT()
• Joins two or more strings into one.
• Example:
SELECT CONCAT(column1, column2, …) AS new_name FROM table_name;
Creates a combined string column.
2. UPPER() / LOWER()
• Converts text to uppercase or lowercase.
• Example:
SELECT UPPER(name), LOWER(department) FROM table_name;
Changes text case consistently.
3. SUBSTRING()
• Extracts a part of a string.
• Example:
SELECT SUBSTRING(name, 2, 4) FROM table_name;
Extracts a substring starting at position 2 with length 4.
4. LENGTH()
• Returns the number of characters in a string.
• Example:
SELECT LENGTH(name) FROM table_name;
Counts characters in values.
5. AS (Alias)
• Renames a column or table temporarily.
• Example:
SELECT name AS instructor_name FROM table_name;
Gives a custom name to the output column.
6. MONTH()
• Extracts the month part from a date.
• Example:
SELECT MONTH(date_column) FROM table_name;
Shows numeric month values (1–12).
7. DATE_FORMAT()
• Formats date values into a given style.
• Example:
SELECT DATE_FORMAT(date_column, '%d/%m/%Y') FROM table_name;
Converts date into readable formats.
8. TIMESTAMPDIFF()
• Finds the difference between two dates in specific units (YEAR, MONTH, DAY).
• Example:
SELECT TIMESTAMPDIFF(MONTH, start_date, end_date) FROM table_name;
Calculates experience durations.
9. MOD()
• Finds remainder from division.
• Example:
SELECT MOD(25, 12);
Useful in splitting date units.
10. DATE_ADD()
• Adds a time interval to a date.
• Example:
SELECT DATE_ADD(CURDATE(), INTERVAL Number DAY);
Finds future dates.
11. DAYNAME()
• Returns the weekday name of a date.
• Example:
SELECT DAYNAME(date_column) FROM table_name;
Gives day of week like “Monday”.
12. CURDATE()
• Returns the current system date.
• Example:
SELECT CURDATE();
Used for calculating durations or referencing today’s date.
13. TRUNCATE()
• Truncates a number to a specified number of decimal places.
• Example:
SELECT TRUNCATE(123.4567, 2);
Gives 123.45.
14. Arithmetic Operators (+, -, , /, power())
• Perform basic math on values.
• Example:
SELECT 2+2;
SELECT POWER(2,2);
Performs operations and returns result.
15. SQRT()
• Returns the square root of a number.
• Example: SELECT SQRT(25);