加入不同类型的列? [英] Joining on columns of different type?

查看:53
本文介绍了加入不同类型的列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果其中一列的类型为int,并且say的值为10,则另一列的类型为varchar,其值为'10'.连接这些值(mySql)是否安全?我是否会得到相同的结果,好像它们都是int类型且值都是10?

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 get the same result as if both were of type int and value 10?

我需要使用不同的类型,因为在一个表中该列是一个自动增量键(因此它必须是int).另一列(在不同的表中)有时可能包含带有字母的值,因此我必须将其设为varchar.您可以预见与此相关的任何大问题吗?或者也许我应该重新考虑一下自己的架构?

I need to have them of different types because in one table the column is an autoincrementing key (so it must be int). The other column (in a different table) may occasionally contain values with letters so I must make it varchar. Can you forsee any huge problems with this or maybe I should rethink my schema?

推荐答案

此方法存在两个问题:

  1. MySQL不会在此类联接上使用索引-根据您的情况(表大小/查询/等...),这可能会或可能不会很重要

  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...)

在数据库设计方面,这听起来有点腥.也许这是我的想象力不佳:-),但我想不出一个可以证明类似情况的例子.如果它是一个表中的主键,则应该是另一个表中的外键.您能更详细地说明您要做什么吗?

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?

这篇关于加入不同类型的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆