SELECT tagid, tagname FROM uchome_mtag WHERE tagname IN
(SELECT tagname FROM uchome_mtag GROUP BY tagname HAVING (COUNT(tagname) > 1)) ORDER BY tagname
跨服务器、数据库、表联合查询
SELECT I.*, M.* FROM OPENROWSET('SQLOLEDB', '192.168.10.2'; 'sa'; '123', [Database1].[dbo].[Table1]) I INNER JOIN (
SELECT DISTINCT P.IPSAppID AppId, P.DepartmentId, C.CategoryId, T.Creator FROM OPENROWSET('SQLOLEDB', '192.168.10.1'; 'sa'; '123', [Database2].[dbo].[table2]) P LEFT JOIN (
SELECT DISTINCT LTRIM(DepartmentId) DepartmentId, UserName Creator FROM OPENROWSET('SQLOLEDB', '192.168.10.1'; 'sa'; '123', [Database3].[dbo].[view1]) WHERE UserName IN
(SELECT DISTINCT Creator FROM OPENROWSET('SQLOLEDB', '192.168.10.1'; 'sa'; '123', [Database1].[dbo].[Table1]) WHERE AppId = '8cefca00-9733-4976-951a-e19346603717' AND CategoryId = 'b14b4852-c0e4-4db6-a91e-704b699a8fa2') ) T
ON P.DepartmentId = T.DepartmentId
LEFT JOIN OPENROWSET('SQLOLEDB', '192.168.10.1'; 'sa'; '123', [Database2].[dbo].[Table3]) C ON C.AppId = P.IPSAppID
WHERE P.ClassId IS NULL AND T.Creator IS NOT NULL AND C.CategoryName = 'activity') M
ON M.Creator = I.Creator
WHERE I.AppId = '8cefca00-9733-4976-951a-e19346603717' AND I.CategoryId = 'b14b4852-c0e4-4db6-a91e-704b699a8fa2'