exists方法:

SELECT top 10 * FROM  t
WHERE (PlanName LIKE '%关键字%' OR remark LIKE '%关键字%'
OR exists(SELECT pp.tpID FROM pp
JOIN points (NOLOCK) p ON p.id = pp.pointID
where p.PointName LIKE '%关键字%' and pp.tpID=t.ID
)
)


left join方法:

;WITH a AS(
SELECT distinct pp.tpID
FROM pp JOIN p ON p.id = pp.pointID
where p.PointName LIKE '%关键字%'
)
SELECT top 10 * FROM t LEFT JOIN a ON t.ID = a.tpID
WHERE (PlanName LIKE '%关键字%' OR remark LIKE '%关键字%' OR isnull(a.tpID,0) >0)