我有以下社区帮助我的查询:
SELECT DISTINCT
a.*
, cast(b.Bytes as varbinary(max)) as Bytes
FROM
(
SELECT
a_inner.Number
, a_inner.Latitude
, a_inner.Longitude
, b_inner.RetiredOn
, a_inner.Name
, a_inner.Zipcode
, b_inner.Oid
FROM
"AM-Martin".dbo.CpCore_Site a_inner
INNER JOIN "AM-Martin".dbo.CpSm_Face b_inner on b_inner.SiteId = a_inner.Oid
WHERE
b_inner.RetiredOn LIKE '%9999%'
AND b_inner.Number LIKE N'%LA%' OR b_inner.Number LIKE N'%LC%' OR b_inner.Number LIKE N'%BH%'
AND b_inner.Latitude > 0.0
) AS a
INNER JOIN "AM-Martin_bin".dbo.CpCore_Image b on a.Oid = b.OwnerId
这给了我以下结果:
每个Oid都分配了多个图像,因此看起来我正在获得重复。我试图将我的结果限制为每个oid一个图像,所以我不会重复。任何帮助将不胜感激。
答案 0 :(得分:0)
如果这是您的Core
表:
SELECT
a_inner.Number
, a_inner.Latitude
, a_inner.Longitude
, b_inner.RetiredOn
, a_inner.Name
, a_inner.Zipcode
, b_inner.OiD
FROM
"AM-Martin".dbo.CpCore_Site a_inner
尝试改变:
LEFT JOIN Instead of Inner Join as well as below query.