Может быть, другой подход?Можете ли вы разделить OR
в вашем JOIN
условии, создать два INNER JOIN
запроса и UNION
их вместе?
SELECT
Source,
FirstName,
LastName,
MiddleName,
Gender,
Age,
DOB,
Address,
Address2,
City,
State,
Zip,
Zip4,
TimeZone,
Income,
HomeValue,
Networth,
MaritalStatus,
IsRenter,
HasChildren,
CreditRating,
Investor,
LinesOfCredit,
InvestorRealEstate,
Traveler,
Pets,
MailResponder,
Charitable,
PolicalDonations,
PoliticalParty,
coalesce(P.ATTOM_ID, T.ATTOM_ID) as ATTOM_ID,
coalesce(P.GEOID, T.GEOID) as GEOID,
Score,
Score1,
Score2,
Score3,
Score4,
Score5,
PropertyLatitude AS Latitude,
PropertyLongitude AS Longitude
FROM `db.ds.Table1` P
INNER JOIN `db.ds.Table2` T ON (P.ATTOM_ID = T.ATTOM_ID)
UNION
SELECT
Source,
FirstName,
LastName,
MiddleName,
Gender,
Age,
DOB,
Address,
Address2,
City,
State,
Zip,
Zip4,
TimeZone,
Income,
HomeValue,
Networth,
MaritalStatus,
IsRenter,
HasChildren,
CreditRating,
Investor,
LinesOfCredit,
InvestorRealEstate,
Traveler,
Pets,
MailResponder,
Charitable,
PolicalDonations,
PoliticalParty,
coalesce(P.ATTOM_ID, T.ATTOM_ID) as ATTOM_ID,
coalesce(P.GEOID, T.GEOID) as GEOID,
Score,
Score1,
Score2,
Score3,
Score4,
Score5,
PropertyLatitude AS Latitude,
PropertyLongitude AS Longitude
FROM `db.ds.Table1` P
INNER JOIN `db.ds.Table2` T ON P.Zip = T. PropertyAddressZIP
AND (
LOWER(P.LastName) = LOWER(T.DeedOwner1NameLast)
OR LOWER(P.LastName) = LOWER(T.PartyOwner1NameLast)
)
AND (
STRPOS(LOWER(P.Address), LOWER(T.PropertyAddressFull) ) > 0
OR STRPOS(LOWER(T.PropertyAddressFull), LOWER(P.Address) ) > 0
)
AND IFNULL(T.PropertyAddressFull,'') != ''