我有以下工作的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
现在,我需要进行以下更改,因为我想获得一个不重复的列表
然后加入另一个表的另一个列-许可证,列为Program
或(Licenses.Program),可以使用两个表中的公共列Version_ID与表xTSTVersions联接。
我想,我必须更改dup查询以获取我想要的记录:
HAVING count(TSTVersion) = 1 ) nondups
现在,我有了非重复列表,如何编辑查询以从另一个表(Licenses.Program)添加新列?
这会变成子选择吗?
最佳答案
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
关于mysql - 如何添加子选择查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27257119/