Chyba je: Toto to vyřeší: SELECT cr.plate, car_id_seq.nextval FROM (SELECT DISTINCT plate FROM cars_rentals) cr