try this: SELECT b.ID ,b.id_surname ,s.id_surname ,s.surname ,b.sortname ,b.name ,b.id_name ,b.sex FROM base b LEFT OUTER JOIN surname s ON s.id_surname = b.id_surname WHERE b.ID like '". $ID ."%' AND s.surname like '".$lit."%' ORDER BY s.surname ASC