连接时选择不同字段
我根据 MySQL 中共享的唯一标识符连接两个大表。因为字段数量很多,所以我不想在 SELECT 之后列出所有字段。相反,我想选择所有字段,但我不希望重复出现重复字段(在本例中为共享唯一标识符)。
对于此示例查询:
SELECT *
FROM Gr3_PracMath_Jan11_D1 as a, student_list_011811 as b
WHERE a.StudentID = b.StudentID
重复字段 StudentID。有办法防止这种情况吗?
I am joining two large tables in MySQL based on a unique identifier they both share. Because there are a large number of fields, I do not want to list out all fields after SELECT. Instead I want to select all fields, but I do not want recurring fields (the shared unique identifier in this case) to be repeated.
With this example query:
SELECT *
FROM Gr3_PracMath_Jan11_D1 as a, student_list_011811 as b
WHERE a.StudentID = b.StudentID
The field StudentID is repeated. Is there a way to prevent this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信,如果您使用 USING 关键字进行显式连接,您将不会得到重复的结果。
I believe that if you do an explicit join with the USING keyword, you won't get a duplicate.
我认为不存在。您可以通过仅列出一半字段来减少工作量:
I don't think there is. You might cut your work by listing only half the fields:
即使列很多,也不列出所有列也是不好的做法。硬着头皮把它们写下来。
It is bad practice to not list out all of the columns, even if there are a lot of them. Just bite the bullet and write them out.