SQL64 找到每个人的任务
描述
有一个person表,主键是id,如下:drop table if exists person;
drop table if exists task;
CREATE TABLE `person` (
`id` int(4) NOT NULL,
`name` varchar(32) NOT NULL,
PRIMARY KEY (`id`));
CREATE TABLE `task` (
`id` int(4) NOT NULL,
`person_id` int(4) NOT NULL,
`content` varchar(32) NOT NULL,
PRIMARY KEY (`id`));
INSERT INTO person VALUES
(1,'fh'),
(2,'tm');
INSERT INTO task VALUES
(1,2,'tm works well'),
(2,2,'tm works well');
输出
1|fh|None
2|tm|tm works well
2|tm|tm works well
SELECT person.id,person.name,task.content FROM person
LEFT JOIN task ON
person.id = task.person_id
ORDER BY person_id