SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table notes (id int, note varchar(64), created_at date); insert into notes values (1, 'note11', now()),(1, 'note12', now()),(1, 'note13', now()),(1, 'note14', now()), (2, 'note21', now()),(2, 'note22', now()),(2, 'note23', now()),(2, 'note24', now()), (3, 'note31', now()),(3, 'note32', now()),(3, 'note33', now()),(3, 'note34', now()); with n as ( select notes.*, row_number() over (partition by id order by created_at) rn from notes ) select id, note from n where rn <= 3;
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear