我有以下工作的mysql查询,它查找重复项:
SELECT TSTVersion_ID,
xTSTVersions.TSTVersion,
TSTPatch
FROM xTSTVersions
INNER JOIN (SELECT TSTVersion
FROM xTSTVersions
GROUP BY TSTVersion
HAVING count(TSTVersion) > 1) dup
ON xTSTVersions.TSTVersion = dup.TSTVersion
现在,我需要进行以下更改,因为我想获得一个不重复的列表 然后从另一个表加入一个额外的列 - 许可证,列是程序 或者(Licenses.Program),可以使用两个表中的公共列Version_ID与表xTSTVersions连接。
我想,我必须更改dup查询以获取我想要的记录:
HAVING count(TSTVersion) = 1 ) nondups
现在,我有我的nondups列表,如何编辑查询以从另一个表(Licenses.Program)添加我的新列?
这会变成子选择吗?
答案 0 :(得分:1)
SELECT TSTVersion_ID,
xTSTVersions.TSTVersion,
TSTPatch,
Licenses.Program
FROM xTSTVersions
INNER JOIN (SELECT TSTVersion
FROM xTSTVersions
GROUP BY TSTVersion
HAVING count(TSTVersion) = 1) dup
ON xTSTVersions.TSTVersion = dup.TSTVersion
INNER JOIN Licenses
ON xTSTVersions.TSTVersion_ID = Licenses.TSTVersion_ID
答案 1 :(得分:-1)
听起来像标准联接:
INNER JOIN xTSTVersions on xTSTVersions.Version_ID = TSVersion.Version_ID