Advertisement: Over 100,000 Jobs Worldwide. Click here to find one for you.

MySQL FAQs
FAQs Categories
Client Server Commands
Database Structure
Table Types or Storage Engines
Indexes
SQL Statements
Table Joins
Funtions and Operators
Tricky Select Queries
Speed Up Queries
Data Back Up
General Questions
Errors
Send This Page to Friend
Enter Friend's Email
Enter Your Email
http://www.kareerlinks.com/jobs/skill/MySQL
 
Home / General Questions / Question No: 157

Why values with spaces do not come into search result?

As per my application requirement, while inserting data into my database table, sometime field value is added padded with spaces at its left-side and sometime at its right-side.  Now, problem occurs when I try a search query to find out desired data against such specific field.  MySQL shows no result against the query whereas I believe that desired data  is available in the table.  I assume that padded spaces with the values cause the problem.  Actually, I am unable to change my application such behavior.  It would be wonder if I get an idea to trim padded spaces from the field while my select queries!

Answer No: 157

To trim spaces from the value of its both sides, MySQL provides TRIM() function.  You can use TRIM to fix spaces  problem in your select queries.  Take an example:

SELECT * FROM tbl_name WHERE TRIM(field_name) = 'searching value'

Comments
Add Comments
Found a bug? Or do you have a better solution for this? Feel free to leave a message:
Leave a comment
Your Name: Your Email Address (optional):
Comment:


Related MySQL FAQs to the Above FAQ

How-can-I-detect-that-MySQL-is-already-installed How can I detect that MySQL is already installed?

What-is-prepared-statement-in-MySQL What is prepared statement in MySQL?

Maximum-number-of-columns-in-a-table Maximum number of columns in a table

Can-I-use-FIELD-CONSTRAINTS-on-MySQL Can I use FIELD CONSTRAINTS on MySQL?

What-are-reserved-words-in-MySQL What are reserved words in MySQL?

How-to-manage-Time-Zone-in-MySQL How to manage Time Zone in MySQL?

What-is-History-of-MySQL What is History of MySQL?

How-does-MySQL-manage-case-sensitivity-of-identifiers How does MySQL manage case sensitivity of identifiers?

What-are-MySQL-connectors-or-client-interfaces What are MySQL connectors or client interfaces?