如何JOIN相似的栏目?
如果我有两个表A和B,那么表A有列:ID,VALUE,ACTIVE 表 B 包含列:ID、NAME、ACTIVE。
A.ACTIVE 和 B.ACTIVE 指的是不同的事物。
之上 从 A 选择 * JOIN B ON A.ID = B.ID
我想分隔 ACTIVE 列,以便我知道哪个是哪个。 我该如何实现这一目标? 谢谢 !
If I have two tables A and B, so that table A has columns: ID, VALUE, ACTIVE
and table B has columns: ID, NAME, ACTIVE.
A.ACTIVE and B.ACTIVE refer to different things.
Upon
SELECT * FROM A
JOIN B ON A.ID = B.ID
I would like to seperate the ACTIVE column so that I know which is which.
How do I go about accomplishing that ?
Thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要使用 * 并限定每一列
Don't use * and qualify each column
我认为你应该重新评估你的命名约定。考虑到来自
ACTIVE
值域的列对于模式(表)中的每个出现(列)应该具有不同的名称,例如,作为第一步,尝试通过使用表名作为前缀来限定它们...但是首先考虑比A
和B
更有意义的名称:)根据 @dispake 的回答,您可以使用
AS
子句来重命名“on the”上的列飞'但这应该被视为如果您需要经常这样做,则会产生代码味道。I think you should re-evaluate your naming convention. Consider that columns from the domain of
ACTIVE
values should have distinct names for each occurrence (column) in the schema (tables) e.g. as a first step try qualifying them by prefixing with the table name... but first consider more meaningful names thanA
andB
:)As per @dispake's answer, you can use
AS
clauses to rename the columns 'on the fly' but this should be regarded as a code smell if you need to do it frequently.