根据表A选择列从表B中选择一列
问题描述:
我正在尝试执行以下操作。根据表A选择列从表B中选择一列
Table A
Name ID
Table B
ID Remark
根据表A名称选择表B备注。
使用名称获取表ID A,则匹配表B中ID从表B.获得注
这是可能的吗?
答
您可以使用where exists
select remark from tableB b where exists (select 1 from tableA a where a.name= [give_name] and a.id=b.id);
或in
select remark from tableB b where b.id in (select id from tableA where name = [give_name]);
答
您可以使用JOIN
SELECT remark FROM tableB b
JOIN tableA a ON a.ID = b.ID
WHERE a.name = ?