From the course: MySQL Essential Training

Unlock this course with a free trial

Join today to access over 24,000 courses taught by industry experts.

Trimming and padding

Trimming and padding - MySQL Tutorial

From the course: MySQL Essential Training

Trimming and padding

- [Bill] Hi, I'm Bill Weinman. There are circumstances where you'll want to trim leading and trailing spaces from a string. For example, when a user types their name into a form, and you need to compare that name to a database column. For this lesson, we'll use the scratch database. So I'll use scratch here, and I'm going to select a row from the customer table where name equals Bill Smith. Now when I execute this, you see we get one row with Bill Smith in the name column. Now imagine that I was comparing this to user input and that user input had a couple extra spaces at the beginning and a couple extra spaces at the end. And now when I execute this query, you'll notice I do not get the result I was looking for. On the other hand, I can trim those spaces if there are any, using the trim function like this. And now I get the result that I was expecting. So let's take a look at this a little bit more closely. We'll just select that trimmed string. And you notice it just says Bill…

Contents