why i cant find data when using = but when use like it show up

问题: i have a table A and one column name nama_dir datatype varchar(50). i want to find this 2134882 so i make a query select * from table A where nama_dir = '2134882' , i...

问题:

i have a table A and one column name nama_dir datatype varchar(50). i want to find this 2134882 so i make a query

select * from table A where nama_dir = '2134882'

, i didnt get any result. but when i change = to like and add '%2134882%' I got the data, can anybody explain why this happening? front and end of the data doesn't have a spacing. why i show up when I'm using like but no =

please help me

Describe table

using trim

not using trim

using like


回答1:

May be there are some spaces, can you try trim?

select * from table A where trim(name_dir) = '2134882'

回答2:

You can write worng DIr name change name_dir to nama_dir:

select * from table A where nama_dir = '2134882'

if you use = operator then it's find specific value in table. it means in your table 2134882 this DIR is not available then data can't show you.

If you use LIKE operator then it's find value which available in 2134882 this data.

  • The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.

  • There are two wildcards used in conjunction with the LIKE operator:


  • % - The percent sign represents zero, one, or multiple characters.

  • _ - The underscore represents a single character


like Operater : WHERE CustomerName LIKE '%or%'

Description : Finds any values that have "or" in any position


回答3:

Perhaps MySQL is treating your value as an integer, try removing quotes

select * from A where name_dir = 2134882

回答4:

Remove the 'Table' from the code. The correct code is:

SELECT * FROM A WHERE name_dir = '2134882'
  • 发表于 2018-07-13 23:39
  • 阅读 ( 302 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除