[英]Select a column from table B based on table A selected column
I'm trying to do the below. 我正在尝试执行以下操作。
Table A
Name ID
Table B
ID Remark
Select Table B Remark based on Table A Name. 根据表A名称选择表B注释。
Use Name to get ID in table A then match ID in table B to get Remark from Table B. 使用名称在表A中获取ID,然后在表B中匹配ID以从表B获取备注。
Is this possible please? 请问这可能吗?
You can use where exists 您可以在存在的地方使用
select remark from tableB b where exists (select 1 from tableA a where a.name= [give_name] and a.id=b.id);
select remark from tableB b where b.id in (select id from tableA where name = [give_name]);
You can use a JOIN 您可以使用JOIN
SELECT remark FROM tableB b
JOIN tableA a ON a.ID = b.ID
WHERE a.name = ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.