Joining on columns of different type?

前端 未结 2 724
滥情空心
滥情空心 2020-12-21 06:38

If one column is of type int and say has a value 10. The other column is of type varchar and has a value of \'10\'. Is it safe to join on these values (mySql), and would I

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-21 07:19

    you should be fine as long as you explicitly convert the data such that the comparison ends up being done in equivalent datatypes.

    based on your description you will need to convert the int datatype to varchar before you make the comparison. take care to trim blanks and be mindful if capitalization is set on your db. also - int comparisons are much faster than varchar comparisons.

提交回复
热议问题