mysql: why comparing a 'string' to 0 gives true?

前端 未结 3 961
灰色年华
灰色年华 2020-12-01 13:09

I was doing some MySQL test queries, and realized that comparing a string column with 0 (as a number) gives TRUE!

select \'string\'         


        
3条回答
  •  执笔经年
    2020-12-01 13:33

    if you want to fix it you can compare two strings:

    select 'string' = convert(0,char) as res --- res = 0
    

提交回复
热议问题