 <p>I come from Oracle background; but I like this beautiful solution.</p> <p>Order the records in <code>CONTACTS</code> by <code>COMPANY_ID</code>, assign each record a unique number, find the minimum and maximum number given to each company, and then, select their two corresponding records:</p> <pre><code>WITH T AS ( SELECT ROWNUM RN, C.* FROM (SELECT CONTACTS.COMPANY_ID, COMPANY.COMPANY_NAME, CONTACTS.NAME, CONTACTS.TEL FROM CONTACTS, COMPANY WHERE CONTACTS.COMPANY_ID = COMPANY.COMPANY_ID ORDER BY CONTACTS.COMPANY_ID ) C ), R AS ( SELECT COMPANY_NAME, MIN(RN) MINR, MAX(RN) MAXR FROM T GROUP BY COMPANY_NAME ) SELECT R.COMPANY_NAME, T1.NAME NAME1, T1.TEL TEL1, T2.NAME NAME2, T2.TEL TEL2 FROM R, T T1, T T2 WHERE R.MINR = T1.RN and R.MAXR = T2.RN </code></pre>