The TRIM function is used in SQL to remove unwanted spaces (or other characters) from the beginning and end of a string.
It is helpful for cleaning up messy or inconsistent data.
SELECT TRIM(column_name)
FROM table_name;TRIMremoves leading and trailing spaces by default.- Some databases allow you to specify which characters to trim.
SELECT TRIM(first_name) AS cleaned_first_name
FROM employees;- This query removes any extra spaces at the start or end of each employee's first name.
- In MySQL and PostgreSQL, you can trim specific characters using
TRIM('x' FROM column_name). - SQL Server uses
LTRIM()for leading spaces andRTRIM()for trailing spaces separately. - Cleaning data before comparisons or reports can prevent hidden errors.
SELECT TRIM(' Hello World ') AS trimmed_text;- This query returns
'Hello World'without the extra spaces.
Describe the problem, challenge, or topic discussed in a video related to SELECT FROM.
What concept was explained or what exercise was solved?
-- Write your SQL code attempt or solution related to SQL COMMAND
SQL COMMANDSQL COMMANDExplanation - Explain what you learned, any key takeaways, or how you solved the problem related to COMMAND._
⬅️ Previous: CHARINDEX or SUBSTRING_INDEX Next ➡️ LEFT & RIGHT