From the course: MySQL Essential Training (2019)

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Trimming and padding

Trimming and padding

- [Instructor] There are circumstances where you'll want to trim leading and trailing spaces from a string. For example, say a user types their name into a form and you need to compare that name to a column in the database. For this lesson, we'll use the scratch database. And so I'll say USE scratch and execute, and now I'll SELECT * FROM the customer table WHERE name LIKE, and I'll put in a couple of spaces before typing Bill Smith and a couple more spaces, and then the quote marks. So inside these quotes I've got Bill Smith but I've got spaces on either side. So when I execute this, you see we get no results. But if I take this Bill Smith with the spaces and I put the function TRIM around it, now when I execute, you see I get a record for Bill Smith. The trim function removes spaces from both the leading and trailing ends of the string. So if I just say SELECT TRIM Bill Smith, you notice that I just get Bill Smith like that but if I do this without the trim, you'll notice that it's…

Contents