drop view if exists view_second_from_cottage; create view view_second_from_cottage as select case obj_type when 403 then 42 when 404 then 428 else 0 end as type, obj_draft_cottage.obj_id as id, 'sell' as offer, obj_city as city, obj_district as district, obj_address as street, obj_add_address as add_address, NULL as `condition`, obj_detail as detail, NULL as accomplish, NULL as floor, obj_floor_house as floor_house, obj_material as material, NULL as layout, obj_square_house as square_all, NULL as square_use, NULL as square_kit, NULL as washroom, NULL as balcon, NULL as telephone, obj_owner as seller_id, obj_price_min as price, obj_price_type as price_type, 0 as price_all_RUR, 0 as price_m_RUR, NULL as rooms, obj_date as date, 'N' as urgent, 'N' as tmp, NULL as source, NULL as bal, 'N' as promo, 0 as imgs, 0 as house, obj_checked_date as checked_date, if(obj_status=91, 'Y', 'N') as active, 'N' as ymap, '' as xls_md5, obj_direction as direction, obj_section_a as distance, 0 as village_id, 0 as source_id, 0 as street_id, obj_phone_num as phone_num, obj_phone_cont as phone_cont, 'N' as disable_stat, '' as disable_stat_comment, '' as failed_fields, '' as failed_checkers, obj_special_offer as special_offer, obj_law_state as law_state, 0 as realty_id, obj_square_house as square_house, obj_square_area as square_area from obj_draft_header inner join obj_draft_cottage on obj_draft_cottage.obj_id = obj_draft_header.obj_id where obj_status=91;