Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
create table tbl ( id serial, user_login text, device text, issued_at timestamp ); insert into tbl (user_login, device, issued_at) values ('ivanov', 'dev1', '2023-01-01'), ('ivanov', 'dev2', '2023-02-01'), ('petrov', 'dev3', '2023-03-01'), ('petrov', 'dev1', '2023-01-01'), ('sidorov', 'dev4', '2023-02-01'); with d as ( select *, row_number() over (partition by user_login order by issued_at) rn from tbl ) select * from d where rn = 1;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear