SQL cheasheet

In same query you can refer to same table twice
select firstname, lastname 
  from names as a,
       names as b
  WHERE a.firstname = b.firstname
    AND a.lastname != b.lastname

Comments