remove distinct from sql query because of postgres