MySQL UPPER and LOWER
The UPPER
function converts a string to uppercase, and the LOWER
function converts a string to lowercase. These functions are useful for case-insensitive comparisons and formatting.
Examples with Tamil Kings
1. Converting King’s Name to Uppercase
SELECT king_name, UPPER(king_name) AS uppercase_name FROM tamil_kings_auto_increment;
Code Explanation: This query converts king_name
to uppercase and renames the result as 'uppercase_name'.
2. Converting King’s Name to Lowercase
SELECT king_name, LOWER(king_name) AS lowercase_name FROM tamil_kings_auto_increment;
Code Explanation: This query converts king_name
to lowercase and renames the result as 'lowercase_name'.
Best Practices
- Use
UPPER
andLOWER
for case-insensitive text comparisons. - Be mindful of the impact on performance when using these functions in WHERE clauses.
Key Takeaways
UPPER
converts text to uppercase, andLOWER
converts text to lowercase.- These functions are useful for formatting and case-insensitive operations.