我有两张桌子:
person
id
name
car
name
person_id
目前查询如下:
SELECT
person.name
car.name
FROM
person, car
WHERE
person.id = car.person_id
现在,如果有一辆车与一个人相关联,这可以正常工作。但是,如果没有,则该人将不会被退回。如果一个人没有车,我想用'No Car'
column中的文本返回一行car.name
。
我有两张桌子:
person
id
name
car
name
person_id
目前查询如下:
SELECT
person.name
car.name
FROM
person, car
WHERE
person.id = car.person_id
现在,如果有一辆车与一个人相关联,这可以正常工作。但是,如果没有,则该人将不会被退回。如果一个人没有车,我想用'No Car'
column中的文本返回一行car.name
。
select person.name, coalesce(car.name, 'no car')
from person
left outer join car on person.id = car.person_id
SELECT person.name, CASE WHEN car.name IS NULL THEN 'no car' ELSE car.name END
FROM person
LEFT JOIN car ON person.id = car.person_id
select person.name, ISNULL(car.name, 'no car')
from person
left join car on person.id = car.person_id