Код:
SELECT SQL_CALC_FOUND_ROWS a.name,tbl7092.etap_Name as tbl7092name, tbl7092.etap_ID as tbl7092id,a.title1,a.title2,a.title3,a.title4,a.title5,a.title6,a.title7,a.control,tbl8874.control_Name as tbl8874name, tbl8874.control_ID as tbl8874id,a.dopcontrol,tbl8882.oblast_Name as tbl8882name, tbl8882.oblast_ID as tbl8882id,tbl611.Region_Name as tbl611name, tbl611.Region_ID as tbl611id,tbl1015.district_Name as tbl1015name, tbl1015.district_ID as tbl1015id,a.street,a.house,a.dop1,tbl614.metro_Name as tbl614name, tbl614.metro_ID as tbl614id,a.metrop,a.metrorast,tbl9253.nsv_Name as tbl9253name, tbl9253.nsv_ID as tbl9253id,tbl9254.nsv_Name as tbl9254name, tbl9254.nsv_ID as tbl9254id,tbl9255.nsv_Name as tbl9255name, tbl9255.nsv_ID as tbl9255id,tbl9256.funczona_Name as tbl9256name, tbl9256.funczona_ID as tbl9256id,a.harakter,a.dop4,tbl618.officetype_Name as tbl618name, tbl618.officetype_ID as tbl618id,a.dop5,tbl621.classhouse_Name as tbl621name, tbl621.classhouse_ID as tbl621id,a.dop6,a.description,a.advantage,a.advantage1,a.advantage2,a.advantage3,a.advantage4,a.object1,a.object3,a.object2,a.dopobject,a.object9,tbl9261.arealand_Name as tbl9261name, tbl9261.arealand_ID as tbl9261id,a.dopland,tbl1208.juridicalstatus_Name as tbl1208name, tbl1208.juridicalstatus_ID as tbl1208id,a.dop7,a.yearbuild,tbl623.timebuild_Name as tbl623name, tbl623.timebuild_ID as tbl623id,a.dop8,a.vvod,a.yearrecon,tbl1081.timerecon_Name as tbl1081name, tbl1081.timerecon_ID as tbl1081id,a.dop10,tbl1209.level_Name as tbl1209name, tbl1209.level_ID as tbl1209id,a.level1,a.floor,a.floor1,a.dop12,a.structure,a.dvor,a.dvor1,a.dopdvor,tbl1210.construction_Name as tbl1210name, tbl1210.construction_ID as tbl1210id,a.dop13,tbl1082.overlap_Name as tbl1082name, tbl1082.overlap_ID as tbl1082id,a.dop14,tbl653.style_Name as tbl653name, tbl653.style_ID as tbl653id,a.dop15,a.height,a.height1,a.height2,a.dop16,a.architech1,a.architech2,a.architech3,a.architech4,a.architech5,a.architech6,a.architech7,a.architech8,a.architech9,a.architech14,a.architech10,a.architech11,a.architech12,a.architech13,a.architech15,a.dop17,a.fasad1,tbl5592.fasad1_Name as tbl5592name, tbl5592.fasad1_ID as tbl5592id,a.fasad3,a.fasad4,a.fasad5,a.dop18,a.entry,a.dop19,tbl1109.heating_Name as tbl1109name, tbl1109.heating_ID as tbl1109id,a.heating1,a.dop20,a.firefighting1,a.firefighting2,a.firefighting3,a.firefighting4,a.firefighting5,a.dop21,a.electrosnab1,a.electrosnab,a.electrosnab2,a.electrosnab3,a.electrosnab4,a.electrosnab5,a.dop22,tbl660.powersupplycategory_Name as tbl660name, tbl660.powersupplycategory_ID as tbl660id,a.dop23,a.automation,a.automation1,a.dop24,a.ventilation1,a.ventilation2,tbl816.ventilation7_Name as tbl816name, tbl816.ventilation7_ID as tbl816id,a.ventilation4,a.ventilation5,a.ventilation6,a.ventilation7,a.ventilation8,a.ventilation9,a.ventilation10,a.dop25,a.internet1,a.internet2,a.dop26,a.opticalfiber,a.dop27,a.provider1,a.provider2,a.provider6,a.provider7,a.provider3,a.provider8,a.provider4,a.provider5,a.provider10,a.provider9,a.provider11,a.dop28,a.telcircuit,a.telcircuitspace,a.dop29,tbl1123.ats_Name as tbl1123name, tbl1123.ats_ID as tbl1123id,a.dop30,a.satelliteline,a.dop31,a.dopcommunication,a.guard2,a.guard3,a.guard4,a.guard5,a.guard7,a.dop32,a.security1,a.security2,a.security3,a.security4,a.security6,a.dop33,a.lift1,a.lift2,a.lift3,a.lift4,a.lift5,a.gruzlift2,a.gruzlift3,a.gruzlift4,tbl1142.liftcompany_Name as tbl1142name, tbl1142.liftcompany_ID as tbl1142id,a.dop34,a.escalator,a.dop35,a.clining,a.dopclining,a.parking1,a.parking2,a.parking3,a.parking4,a.parking5,a.parking6,a.parking7,a.parking8,a.parking8km,a.parking9,a.parking9km,a.parking10,a.parking10km,a.park10kmk,a.parking11,a.parking11km,a.parking12,a.parking12km,a.parking13,a.parking13km,a.parking14,a.parking15,a.parking14km,a.dop36,a.parkingguard,a.parkingguard1,a.parkingguard2,a.parkingguard4,a.dop37,tbl685.tenantry_Name as tbl685name, tbl685.tenantry_ID as tbl685id,a.dop39,a.tenantryanchor,a.infrastructure1,a.infrastructure2,a.infrastructure3,a.infrastructure4,a.infrastructure5,a.infrastructure6,a.infrastructure7,a.infrastructure8,a.infrastructure8km,a.infrastructure10,a.infrastructure11,a.infrastructure12,a.infrastructure13,a.infrastructure14,a.infrastructure15,a.infrastructure16,a.infrastructure17,a.infrastructure18,a.infrastructure19,a.infrastructure20,a.infrastructure21,a.infrastructure21km,a.infrastructure22,a.infrastructure22km,a.infrastructure23,a.infrastructure23km,a.infrastructure24,a.infrastructure24km,a.infrastructure25,a.infrastructure26,a.dop40,a.doptransport,a.dop42,a.information,IF(a.imgsmall<>'',CONCAT('/netcat_files/710_',a.Message_ID,RIGHT(SUBSTRING_INDEX(a.imgsmall,':',1), LOCATE('.',REVERSE(SUBSTRING_INDEX(a.imgsmall,':',1))))),''), SUBSTRING_INDEX(a.imgsmall,':',1), SUBSTRING_INDEX(SUBSTRING_INDEX(a.imgsmall,':',-2),':',1), SUBSTRING_INDEX(a.imgsmall,':',-1),IF(a.img1<>'',CONCAT('/netcat_files/1009_',a.Message_ID,RIGHT(SUBSTRING_INDEX(a.img1,':',1), LOCATE('.',REVERSE(SUBSTRING_INDEX(a.img1,':',1))))),''), SUBSTRING_INDEX(a.img1,':',1), SUBSTRING_INDEX(SUBSTRING_INDEX(a.img1,':',-2),':',1), SUBSTRING_INDEX(a.img1,':',-1),IF(a.img2<>'',CONCAT('/netcat_files/1010_',a.Message_ID,RIGHT(SUBSTRING_INDEX(a.img2,':',1), LOCATE('.',REVERSE(SUBSTRING_INDEX(a.img2,':',1))))),''), SUBSTRING_INDEX(a.img2,':',1), SUBSTRING_INDEX(SUBSTRING_INDEX(a.img2,':',-2),':',1), SUBSTRING_INDEX(a.img2,':',-1),IF(a.img3<>'',CONCAT('/netcat_files/1011_',a.Message_ID,RIGHT(SUBSTRING_INDEX(a.img3,':',1), LOCATE('.',REVERSE(SUBSTRING_INDEX(a.img3,':',1))))),''), SUBSTRING_INDEX(a.img3,':',1), SUBSTRING_INDEX(SUBSTRING_INDEX(a.img3,':',-2),':',1), SUBSTRING_INDEX(a.img3,':',-1),IF(a.img4<>'',CONCAT('/netcat_files/1012_',a.Message_ID,RIGHT(SUBSTRING_INDEX(a.img4,':',1), LOCATE('.',REVERSE(SUBSTRING_INDEX(a.img4,':',1))))),''), SUBSTRING_INDEX(a.img4,':',1), SUBSTRING_INDEX(SUBSTRING_INDEX(a.img4,':',-2),':',1), SUBSTRING_INDEX(a.img4,':',-1),IF(a.img5<>'',CONCAT('/netcat_files/1013_',a.Message_ID,RIGHT(SUBSTRING_INDEX(a.img5,':',1), LOCATE('.',REVERSE(SUBSTRING_INDEX(a.img5,':',1))))),''), SUBSTRING_INDEX(a.img5,':',1), SUBSTRING_INDEX(SUBSTRING_INDEX(a.img5,':',-2),':',1), SUBSTRING_INDEX(a.img5,':',-1),a.ID,sub.Hidden_URL, cc.EnglishName, a.Message_ID, a.User_ID, a.IP, a.UserAgent, a.LastUser_ID, a.LastIP, a.LastUserAgent, a.Priority, cc.Sub_Class_ID, sub.Subdivision_ID, a.Checked, a.Created, a.LastUpdated, a.Keyword FROM (Message61 AS a ) LEFT JOIN Classificator_etap AS tbl7092 ON a.etap=tbl7092.etap_ID LEFT JOIN Classificator_control AS tbl8874 ON a.control1=tbl8874.control_ID LEFT JOIN Classificator_oblast AS tbl8882 ON a.oblast=tbl8882.oblast_ID LEFT JOIN Classificator_Region AS tbl611 ON a.city=tbl611.Region_ID LEFT JOIN Classificator_district AS tbl1015 ON a.district=tbl1015.district_ID LEFT JOIN Classificator_metro AS tbl614 ON a.metro=tbl614.metro_ID LEFT JOIN Classificator_nsv AS tbl9253 ON a.harakter1=tbl9253.nsv_ID LEFT JOIN Classificator_nsv AS tbl9254 ON a.harakter2=tbl9254.nsv_ID LEFT JOIN Classificator_nsv AS tbl9255 ON a.harakter3=tbl9255.nsv_ID LEFT JOIN Classificator_funczona AS tbl9256 ON a.harakter4=tbl9256.funczona_ID LEFT JOIN Classificator_officetype AS tbl618 ON a.type=tbl618.officetype_ID LEFT JOIN Classificator_classhouse AS tbl621 ON a.class=tbl621.classhouse_ID LEFT JOIN Classificator_arealand AS tbl9261 ON a.arealand=tbl9261.arealand_ID LEFT JOIN Classificator_juridicalstatus AS tbl1208 ON a.juridicalstatus=tbl1208.juridicalstatus_ID LEFT JOIN Classificator_timebuild AS tbl623 ON a.timebuild=tbl623.timebuild_ID LEFT JOIN Classificator_timerecon AS tbl1081 ON a.timerecon=tbl1081.timerecon_ID LEFT JOIN Classificator_level AS tbl1209 ON a.level=tbl1209.level_ID LEFT JOIN Classificator_construction AS tbl1210 ON a.construction=tbl1210.construction_ID LEFT JOIN Classificator_overlap AS tbl1082 ON a.overlap=tbl1082.overlap_ID LEFT JOIN Classificator_style AS tbl653 ON a.style=tbl653.style_ID LEFT JOIN Classificator_fasad1 AS tbl5592 ON a.fasad2=tbl5592.fasad1_ID LEFT JOIN Classificator_heating AS tbl1109 ON a.heating=tbl1109.heating_ID LEFT JOIN Classificator_powersupplycategory AS tbl660 ON a.powersupplycategory=tbl660.powersupplycategory_ID LEFT JOIN Classificator_ventilation7 AS tbl816 ON a.ventilation3=tbl816.ventilation7_ID LEFT JOIN Classificator_ats AS tbl1123 ON a.ats=tbl1123.ats_ID LEFT JOIN Classificator_liftcompany AS tbl1142 ON a.brandlift=tbl1142.liftcompany_ID LEFT JOIN Classificator_tenantry AS tbl685 ON a.tenantry=tbl685.tenantry_ID LEFT JOIN Subdivision AS sub ON sub.Subdivision_ID=a.Subdivision_ID LEFT JOIN Sub_Class AS cc ON cc.Sub_Class_ID=a.Sub_Class_ID WHERE 1 AND a.Parent_Message_ID=".$parent_message." AND sub.Catalogue_ID='1' AND a.Subdivision_ID='361' AND a.Sub_Class_ID='236' AND a.Checked=1 ORDER BY a.Priority DESC, a.LastUpdated DESC LIMIT 0,20