with usertable as ( 
SELECT s.tlmfID,p.tlExtNum,p.tlSeqNum,dt.aperMag3 AS tileMag3, dt.aperMag9
AS tileMag9,mt.fileName AS tileFile, do1.aperMag3 AS o1Mag3, do1.aperMag9 AS
o1Mag9, mo1.fileName AS o1File, do2.aperMag3 AS o2Mag3, do2.aperMag9 AS
o2Mag9, mo2.fileName AS o2File, do3.aperMag3 AS o3Mag3, do3.aperMag9 AS
o3Mag9, mo3.fileName AS o3File, do4.aperMag3 AS o4Mag3, do4.aperMag9 AS
o4Mag9, mo4.fileName AS o4File, do5.aperMag3 AS o5Mag3, do5.aperMag9 AS
o5Mag9, mo5.fileName AS o5File, do6.aperMag3 AS o6Mag3, do6.aperMag9 AS
o6Mag9, mo6.fileName AS o6File FROM vhsTileSet AS s, vhsTilePawTDOnly AS p, vhsDetection AS dt, Multiframe
AS mt, vhsDetection AS do1, Multiframe AS mo1, vhsDetection AS do2,
Multiframe AS mo2, vhsDetection AS do3, Multiframe AS mo3, vhsDetection AS
do4, Multiframe AS mo4, vhsDetection AS do5, Multiframe AS mo5, vhsDetection
AS do6, Multiframe AS mo6
WHERE s.tileSetID=p.tileSetID AND ((s.ra>115 AND s.ra<125 AND s.dec>-65. AND
s.dec<-55.) OR s.tileSetID<0) AND s.tlmfID=dt.multiframeID AND
p.tlExtNum=dt.extNum AND p.tlSeqNum=dt.seqNum AND s.tlmfID=mt.multiframeID
AND s.o1mfID=do1.multiframeID AND p.o1ExtNum=do1.extNum AND
p.o1SeqNum=do1.seqNum AND s.o1mfID=mo1.multiframeID AND
s.o2mfID=do2.multiframeID AND p.o2ExtNum=do2.extNum AND
p.o2SeqNum=do2.seqNum AND s.o2mfID=mo2.multiframeID AND
s.o3mfID=do3.multiframeID AND p.o3ExtNum=do3.extNum AND
p.o3SeqNum=do3.seqNum AND s.o3mfID=mo3.multiframeID AND
s.o4mfID=do4.multiframeID AND p.o4ExtNum=do4.extNum AND
p.o4SeqNum=do4.seqNum AND s.o4mfID=mo4.multiframeID AND
s.o5mfID=do5.multiframeID AND p.o5ExtNum=do5.extNum AND
p.o5SeqNum=do5.seqNum AND s.o5mfID=mo5.multiframeID AND
s.o6mfID=do6.multiframeID AND p.o6ExtNum=do6.extNum AND
p.o6SeqNum=do6.seqNum AND s.o6mfID=mo6.multiframeId
)
SELECT s.sourceID,s.ra,s.dec, ymatch.tileFile AS yTileFile, ymatch.tileMag3
AS yTileMag3, ymatch.tileMag9 AS yTileMag9,
ymatch.o1File AS yOff1File, ymatch.o1Mag3 AS yOff1Mag3, ymatch.o1Mag9 AS
yOff1Mag9, ymatch.o2File AS yOff2File, ymatch.o2Mag3 AS yOff2Mag3,
ymatch.o2Mag9 AS yOff2Mag9, ymatch.o3File AS yOff3File, ymatch.o3Mag3 AS
yOff3Mag3, ymatch.o3Mag9 AS yOff3Mag9, ymatch.o4File AS yOff4File,
ymatch.o4Mag3 AS yOff4Mag3, ymatch.o4Mag9 AS yOff4Mag9, ymatch.o5File AS
yOff5File, ymatch.o5Mag3 AS yOff5Mag3, ymatch.o5Mag9 AS yOff5Mag9,
ymatch.o6File AS yOff6File, ymatch.o6Mag3 AS yOff6Mag3, ymatch.o6Mag9 AS
yOff6Mag9,
jmatch.tileMag3 AS jTileMag3, jmatch.tileMag9 AS jTileMag9,
jmatch.o1File AS jOff1File, jmatch.o1Mag3 AS jOff1Mag3, jmatch.o1Mag9 AS
jOff1Mag9, jmatch.o2File AS jOff2File, jmatch.o2Mag3 AS jOff2Mag3,
jmatch.o2Mag9 AS jOff2Mag9, jmatch.o3File AS jOff3File, jmatch.o3Mag3 AS
jOff3Mag3, jmatch.o3Mag9 AS jOff3Mag9, jmatch.o4File AS jOff4File,
jmatch.o4Mag3 AS jOff4Mag3, jmatch.o4Mag9 AS jOff4Mag9, jmatch.o5File AS
jOff5File, jmatch.o5Mag3 AS jOff5Mag3, jmatch.o5Mag9 AS jOff5Mag9,
jmatch.o6File AS jOff6File, jmatch.o6Mag3 AS jOff6Mag3, jmatch.o6Mag9 AS
jOff6Mag9,
hmatch.tileMag3 AS yTileMag3, hmatch.tileMag9 AS hTileMag9,
hmatch.o1File AS hOff1File, hmatch.o1Mag3 AS hOff1Mag3, hmatch.o1Mag9 AS
hOff1Mag9, hmatch.o2File AS hOff2File, hmatch.o2Mag3 AS hOff2Mag3,
hmatch.o2Mag9 AS hOff2Mag9, hmatch.o3File AS hOff3File, hmatch.o3Mag3 AS
hOff3Mag3, hmatch.o3Mag9 AS hOff3Mag9, hmatch.o4File AS hOff4File,
hmatch.o4Mag3 AS hOff4Mag3, hmatch.o4Mag9 AS hOff4Mag9, hmatch.o5File AS
hOff5File, hmatch.o5Mag3 AS hOff5Mag3, hmatch.o5Mag9 AS hOff5Mag9,
hmatch.o6File AS hOff6File, hmatch.o6Mag3 AS hOff6Mag3, hmatch.o6Mag9 AS
hOff6Mag9,
ksmatch.tileMag3 AS ksTileMag3, ksmatch.tileMag9 AS yTileMag9,
ksmatch.o1File AS ksOff1File, ksmatch.o1Mag3 AS ksOff1Mag3,
ksmatch.o1Mag9 AS ksOff1Mag9, ksmatch.o2File AS ksOff2File, ksmatch.o2Mag3
AS ksOff2Mag3, ksmatch.o2Mag9 AS ksOff2Mag9, ksmatch.o3File AS ksOff3File,
ksmatch.o3Mag3 AS ksOff3Mag3, ksmatch.o3Mag9 AS ksOff3Mag9, ksmatch.o4File
AS ksOff4File, ksmatch.o4Mag3 AS ksOff4Mag3, ksmatch.o4Mag9 AS ksOff4Mag9,
ksmatch.o5File AS ksOff5File, ksmatch.o5Mag3 AS ksOff5Mag3, ksmatch.o5Mag9
AS ksOff5Mag9, ksmatch.o6File AS ksOff6File, ksmatch.o6Mag3 AS ksOff6Mag3,
ksmatch.o6Mag9 AS ksOff6Mag9
FROM vhsSource AS s,vhsMergeLog AS l, usertable AS ymatch, usertable AS
jmatch, usertable AS hmatch,usertable AS ksmatch
WHERE l.frameSetID=s.frameSetID AND l.ra>115. AND l.ra<125 AND l.dec>-65.
AND l.dec<-55. AND l.jmfID=jmatch.tlmfID AND l.jeNum=jmatch.tlExtNum AND
s.jseqNum=jmatch.tlSeqNum AND l.ymfID=ymatch.tlmfID AND
l.yeNum=ymatch.tlExtNum AND s.yseqNum=ymatch.tlSeqNum AND
l.hmfID=hmatch.tlmfID AND l.heNum=hmatch.tlExtNum AND
s.hseqNum=hmatch.tlSeqNum AND l.ksmfID=ksmatch.tlmfID AND
l.kseNum=ksmatch.tlExtNum AND s.ksseqNum=ksmatch.tlSeqNum