SELECT sd.id , sd.lng_parent , sd.title, sd.image, sd.link_file , sd.catalogue AS doc_catalogue , sd.langue AS doc_langue , sdc.title AS categorie , sdc.id AS categorie_id , sg.title AS gamme_title , sg.id AS gamme_id , sda.id_association AS id_modele FROM #__socorex_documents AS sd LEFT JOIN #__socorex_documents_cats AS sdc ON (sdc.lng_parent = sd.id_categorie AND sdc.langue = 'en-GB' ) LEFT JOIN #__socorex_documents_associations AS sda ON ( sda.id_document = sd.lng_parent ) LEFT JOIN #__socorex_gammes AS sg ON sg.lng_parent = sda.gamme WHERE (( sd.state=1 AND sd.link_file != '' AND sd.link_file IS NOT NULL AND sg.state=1 AND sdc.state=1 AND sd.catalogue = 2 AND sd.langue = 'en-GB' ) OR ( `sda`.association = 'NoModel' AND sd.state = 1 AND sd.link_file != '' AND sd.link_file IS NOT NULL AND sd.langue = 'en-GB' AND sd.catalogue = 2 ) ) GROUP BY sd.id ORDER BY sd.is_general_catalog DESC, sdc.ordering ASC , sd.ordering ASC