mysql query only works when value is compared with primary key I'm working with this table:

mysql&gt; describe dispositivos;
+-----------+-------------+------+-----+---------+-------+
| Field     | Type        | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| sn        | varchar(25) | NO   | PRI | NULL    |       |
| device_id | varchar(25) | YES  |     | NULL    |       |
| ip_adress | varchar(25) | YES  |     | NULL    |       |
+-----------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)


I've noticed that when I type a query like this:

mysql&gt; select * from dispositivos WHERE sn = "SAL1027TVGH";
+-------------+---------------+------------------+
| sn          | device_id     | ip_adress        |
+-------------+---------------+------------------+
| SAL1027TVGH |  CU_DGIE_6509 |  148.228.110.254 |
+-------------+---------------+------------------+
1 row in set (0.00 sec)


everything goes fine, but if I search by any other field, the query is not working.

mysql&gt; select * from dispositivos WHERE ip_adress ="148.228.110.254";
Empty set (0.00 sec)

mysql&gt; select * from dispositivos WHERE device_id ="CU_DGIE_6509";
Empty set (0.00 sec)


Do you know why this is happening?

there are other tables, but the problem just affect this one, it is being filled automatically with LOAD DATA LOCAL INFILE. 

thanks.
Look at the output of your select statement: it seems you have a leading blank in your values.