select * from commercial01 left join lids on (commercial01.comid = lids.propid and lids.type='com') left join comcontact on (commercial01.comid = comcontact.comid and comcontact.ctype='1') where commercial01.status='active' and commercial01.region = 'm' and ( 0 or 1) and commercial01.location ='23' ORDER BY ltype ASC, randomOrder LIMIT -20,20