SELECT
    k.kodas AS client_code,
    trim(concat_ws(' ', k.vardas, k.pavarde)) AS name,
    trim(concat_ws(', ',
        concat_ws(' ', g.pav, k.namas, k.butas),
        m.pav,
        r.pav
    )) AS address,
    k.email,
    k.tscreated AS creation_date,
    k.mob_telefonas AS mobile_phone,
    k.telefonas AS phone,
    k.ak AS personal_code,
    k.im_kodas AS company_code,
    k.pvm_kodas AS vat_code,
    k.tipas AS person_type,
    k.ucreated
FROM klientas k
LEFT JOIN gatve g ON g.gatveid = k.gatveid
LEFT JOIN miestas m ON m.miestasid = k.miestasid
LEFT JOIN rajonas r ON r.rajonasid = k.rajonasid
ORDER BY k.kodas;
