SELECT SQL_CALC_FOUND_ROWS pd46.*, IF((pd46.price_eq IS NULL OR pd46.price_eq=0) AND (pd46.price_gt IS NULL OR pd46.price_gt=0) AND (pd46.price_lt IS NULL OR pd46.price_lt=0), 1, 0) AS o2313_isnull, IF(pd46.price_eq IS NULL, IF(pd46.price_gt IS NULL, 0, pd46.price_gt), pd46.price_eq) as o2313_average FROM pd46 JOIN pd_moption AS mo525 JOIN pd_moption AS mo2311 LEFT JOIN pd_tube ON (pd46.tube=pd_tube.ref_id) WHERE (pd46.approved=1) AND (pd46.published=1) AND (pd46.account IN (101163%7C101171%7C1004584%7C1105315,101171,1004584,1105315) ) AND (pd46.condoheight=mo525.ref_id) AND (mo525.option_id='856') AND (pd46.roomtypes=mo2311.ref_id) AND (mo2311.option_id='2304') AND ((pd46.amphoe IN (933,925,908,914,916,919,926) OR pd46.street IN (27,30,72,107,134,137,189,190,191,262,406,516,198,51,94,132,197,198,228,229,230,429,566,98,101,129,147,169,195,237,428,604,630,694,90,102,116,418,430,696,697,698,699,700,701,702,703,704,705,207,706,707,708,709,710,711,712,391,222,223,224,208,209,713,714,715,716,717,718,719,720,210,721,722,225,723,724,392,725,726,572,211,727,728,729,730,731,732,733,367,212,734,735,213,736,737,738,739,740,513,741,214,215,216,217,218,743,744,219,746,748,398,220,221,752,753,754,755,756,757,758,759,203,204) OR (street='28' AND amphoe IN (908)) OR (street='28' AND amphoe IN (925)) OR (street='28' AND amphoe IN (933)) OR (street='70' AND amphoe IN (925)) OR (street='70' AND amphoe IN (933)) OR (street='104' AND amphoe IN (891)) OR (street='104' AND amphoe IN (933)) OR (street='28' AND amphoe IN (908)) OR (street='28' AND amphoe IN (914)) OR (street='70' AND amphoe IN (914)) OR (street='202' AND amphoe IN (916)) OR (street='98' AND amphoe IN (916)) OR (street='115' AND amphoe IN (894)) OR (street='115' AND amphoe IN (919)) OR (street='127' AND amphoe IN (916)) OR (street='127' AND amphoe IN (926)) OR (street='148' AND amphoe IN (919)) OR (street='148' AND amphoe IN (926)) OR (street='151' AND amphoe IN (919)) OR (street='151' AND amphoe IN (926)) OR (street='174' AND amphoe IN (926)) OR (street='227' AND amphoe IN (919)))) AND (pd46.province IN (1,19,24,28,59) ) AND ((pd_tube.ref_id IS NOT NULL)) GROUP BY pd46.crkp_id, pd46.tube ORDER BY pinned DESC, crkp_id DESC, o2313_isnull ASC, o2313_average , pd46.soldout ASC LIMIT 10