在MySQL中的联接上选择不同的字段 [英] Select Distinct Field on Join in MySQL

查看:216
本文介绍了在MySQL中的联接上选择不同的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在基于两个共享的唯一标识符联接MySQL中的两个大表.因为字段很多,所以我不想在SELECT之后列出所有字段.相反,我想选择所有字段,但是我不想重复重复出现的字段(在这种情况下为共享的唯一标识符).

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.

使用此示例查询:

SELECT *
FROM Gr3_PracMath_Jan11_D1 as a, student_list_011811 as b 
WHERE a.StudentID = b.StudentID

字段StudentID重复.有办法防止这种情况吗?

The field StudentID is repeated. Is there a way to prevent this?

谢谢您的帮助.

推荐答案

我相信,如果使用USING关键字进行显式联接,则不会重复.

I believe that if you do an explicit join with the USING keyword, you won't get a duplicate.

SELECT *
FROM Gr3_PracMath_Jan11_D1
LEFT JOIN student_list_011811 
USING (StudentID)

这篇关于在MySQL中的联接上选择不同的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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