SELECT m.sgr_department_code
, IF(m.sgr_machine_short_desc_zh <> '', m.sgr_machine_short_desc_zh,m.sgr_machine_short_desc)
, m.sgr_machine_type_code
-- , m.marketing_description
, mt.sgr_machine_type_desc_zh as sgr_machine_type_desc
, m.sgr_machine_brand
, trim(concat(m.sgr_machine_model,' ',sgr_machine_submodel)) as sgr_machine_model
, m.sgr_machine_year
, m.sgr_machine_ID
, m.marketing_status as status
, u.url_name_zh as url_name
, mt.Miscellaneous
, (select url_image from TMBR_WEB_URLS where url_action = 'SEARCH' and url_name like 'BD-%' and url_brand = m.sgr_machine_brand order by url_count desc limit 1) url_image
FROM TMBR_WEB_MACHINES as m
, TMBR_WEB_MACHINE_TYPES mt
, TMBR_WEB_DEPARTMENTS d
, TMBR_WEB_URLS u
WHERE d.sgr_department_code = m.sgr_department_code
and mt.sgr_machine_type = m.sgr_machine_type_code
and u.url_name Like 'R-%'
and u.url_action = 'SPEC'
and u.url_dept = m.sgr_department_code
and u.url_m_type = m.sgr_machine_type_code
and u.url_ref = m.sgr_machine_ID AND m.sgr_department_code= ? AND mt.sgr_machine_type = ?
-- AND m.sgr_department_code = 'TP'
-- AND m.sgr_machine_type_code = 'TPSE'
AND m.web_published = '1'
ORDER BY
m.sgr_machine_year ASC
, sgr_machine_ID DESC
LIMIT 0, 18