Fejlen er: Dette vil løse det: SELECT cr.plate, car_id_seq.nextval FROM (SELECT DISTINCT plate FROM cars_rentals) cr