query = ("""SELECT DISTINCT
L.ra, L.dec, L.type,
S.z, S.plug_ra, S.plug_dec, S.class, S.specobjid,
P.dered_mag_g, P.dered_mag_r, P.dered_mag_w1, P.dered_mag_w2, P.dered_mag_w3,
P.dered_mag_w4, P.dered_mag_z
FROM ls_dr7.x_sdss_dr14_specobj_1p5 as X
JOIN ls_dr7.dr7_specobj_dr14 as L ON L.decals_id = X.decals_id
JOIN sdss_dr14.specobj as S ON S.specobjid = X.specobjid
JOIN ls_dr7.tractor_primary as P ON P.decals_id = X.decals_id
WHERE S.z > 0 and S.z < 0.02 and S.class != 'STAR' and L.ra BETWEEN %s and %s and L.dec
BETWEEN %s and %s limit 2000000""") %(100,270,-5,30)