Joining on columns of different type?

前端 未结 2 726
滥情空心
滥情空心 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:30

    There are two problems with this approach:

    1. MySQL will not use indexes on such join - which may or may not be a huge deal depending on your circumstances (table size / query / etc...)

    2. Database design-wise this smells fishy. Perhaps it's my poor imagination :-) but I can't think of an example where something like this would be justified. If it's a primary key in one table, it should be foreign key in another. Can you explain what you're trying to do in more detail?

提交回复
热议问题