表A有字段id,name,id是主键,表B有字段b_id,id(外键),查询结果如下图格式显示

2024-12-23 03:19:40
推荐回答(4个)
回答1:

SELECT A.id, A.name, C.name FROM A INNER JOIN B ON A.id=B.id INNER JOIN A AS C ON B.b_id=C.id

回答2:

没有读懂题目的意思,能否将题目再详尽的说明一下。

回答3:

name2是表B的字段么

回答4:

话说那个name2是哪来的……
如果name2是从B表来的话
select A.id,A.name,B.name2
from A,B
where A.id = B.id
union all
select null,null,name2
from B
where B.id not in (select id from A)