我有以下Sybase sql语句,其中包含使用语法= *的右外部联接(我认为)。我试图在mysql中复制此文件,但失败极了。谁能建议我在发件人部分中陈述正确的外部联接。
SELECT database1.inst.regionAbb,
database1.inst.regionalCode,
database1.inst.instCode,
database1.inst.name,
database1.inst.yCode,
database1.blac.customerCode,
database1.inst.transportCode,
database1.inst.Agreement,
database1.addr.telephone,
database1.addr.fax,
database1.addr.email,
database1.addr.id contactaddr,
database1.inst.nameAbb,
database1.inst.messageType,
database1.inst.closedFrom,
database1.inst.closedTo,
database1.inst.costScheme1,
database1.inst.costScheme2,
database1.inst.costScheme3,
database1.inst.costScheme4,
database1.inst.costScheme5,
now() updated
FROM database1.Table1 inst,
database1.Table2 addr,
database1.Table3 blac
WHERE ((database1.addr.instCode = database1.inst.instCode) **
AND ((database1.blac.instCode =* database1.inst.instCode)**
AND (database1.blac.preferred = "Y")))
AND ((database1.addr.id = database1.inst.Address
AND database1.inst.lendingTable2 != 0)
OR (database1.addr.id = database1.inst.mainTable2
AND database1.inst.lendingTable2 = 0))
最佳答案
我对Sybase不熟悉,但是我认为这是您想要的:
SELECT * FROM
FROM database1.Table1 inst,
INNER JOIN database1.Table2 addr ON addr.instCode = inst.instCode
LEFT JOIN database1.Table3 blac ON blac.instCode = inst.instCode
WHERE blac.preferred = "Y"
OR (blac.preferred IS NULL AND
((addr.id = inst.Address AND inst.lendingTable2 != 0)
OR (addr.id = inst.mainTable2 AND inst.lendingTable2 = 0)))
这假设它仅对是否有
blac
记录进行最终检查-如果您实际上要进行检查是否没有blac
记录或blac.preferred != 'Y'
,那么您可以删除blac.preferred IS NULL AND
以及多余的内容对括号。