I have the following schema in my database:
CREATE TABLE users (
id integer NOT NULL
);
CREATE TABLE survey_results (
id integer NOT NULL,
name text,
user_id integer,
created_at timestamp without time zone
);
INSERT INTO users (id)
VALUES (1);
INSERT INTO survey_results (id, name, user_id, created_at)
VALUES (1, 'TEST 1', 1, now());
INSERT INTO survey_results (id, name, user_id, created_at)
VALUES (2, 'TEST 2', 1, now());
INSERT INTO survey_results (id, name, user_id, created_at)
VALUES (3, 'TEST 3', 1, now());
Now I want to get name of first and last user survey_result in one query, so result should look like this
id first last
1 TEST1 TEST2
How can I do this in PostgreSQL?
Here is sqlfiddle with this schema: https://www.db-fiddle.com/f/aC2DrJXqmJc1ZLkdEjLnht/0