By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE people (numid INTEGER PRIMARY KEY, name TEXT);
INSERT INTO people VALUES
(1,'Person1'), (2,'Person2'), (3,'Person3');
CREATE TABLE chosenNumbers (numid INTEGER PRIMARY KEY, chosen_num INTEGER, type TEXT, personid INTEGER, FOREIGN KEY(personid) REFERENCES people(numid));
INSERT INTO chosenNumbers VALUES
(1,101,'first',1), (2,102,'second',1), (3,201,'first',2), (4,202,'second',2);
SELECT p.*,
MAX(CASE WHEN c.type = 'first' THEN c.chosen_num END) AS first_num,
MAX(CASE WHEN c.type = 'second' THEN c.chosen_num END) AS second_num
FROM people AS p LEFT JOIN chosenNumbers AS c
ON p.numid = c.personid
GROUP BY p.numid;
numid | name | first_num | second_num |
---|---|---|---|
1 | Person1 | 101 | 102 |
2 | Person2 | 201 | 202 |
3 | Person3 | null | null |