I've the next query:

SELECT s.id,
       s.name,
       s.prom,
       s.some_other_field,
       ... many more fields also
FROM mytable s
INNER JOIN (on some other tables etc.)

Within the situation where you will find a lot more than 6 records with similar title (s.title), I wish to group these products together as you row (I do not care which other information is arranged into that row, i.e. the very first record of this group could be fine).

Is possible in Postgres? I suppose it's a conditional group by in this way that I wish to group the records in which the same title seems a lot more than 6 occasions, although coming back the rest of the records normally.

Any assistance is much appreciated - thanks!

this can be done:

select * from (

    SELECT s.id,
           s.name,
           s.prom,
           s.some_other_field,
           ... many more fields also,
           row_number() over (partition by s.name order by s.id) as rnk,
           count(*) over (partition by s.name) cnt
    FROM mytable s
    INNER JOIN (on some other tables etc.)

) a
where cnt < 6 or (cnt >=6 and rnk = 1)