SQL joins with duplicated records and NULL values