简体   繁体   English

根据表A选定的列从表B中选择一列

[英]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); 

or in

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.

相关问题 MySQL Select 将 A 列与 B 列存在的表不同,或者如果 B 列不存在,则基于 C 列的最新 - MySQL Select distinct column A from table where column B exists or if none with column B then latest based on column C MYSQL:从表B中选择列(如果存在),否则从表A中选择 - MYSQL: Select column from table B if it exists, otherwise from table A 从表中选择A列或B列中的值 - Select from table where value in column A or column B 从表中选择 [列 a],其中没有 [列 b = 任意值] 的实例 - Select [column a] from table where there are no instances of [column b = arbitrary value] 在表A中选择需要表B中信息的列的最简单方法是什么? - Simplest way to select a column in table A that need info from table B? 从表A中选择*,但在第1列中显示它与表B中的匹配项 - Select * from Table A but in Column 1 show what it matches up with in Table B 插入表B选择*从表A,但表B中有一个额外的列,是否可以? - Insert Into Table B Select * From Table A, but with an extra column in Table B, is it possible? 如果表 B 小于表 B 列 col1 比较表 A,则从表 B 中选择行 - Select rows from table B if it is less than Table B Column col1 comparing Table A 根据同一表中的列值从表中选择记录 - Select records from a table based on column value from same table SELECT Column_B FROM tableA where Column_A =? AND SELECT 列 C 来自表 B,其中 B 列 = 表 1 中的 B 列? - SELECT Column_B FROM tableA where Column_A = ? AND SELECT Column C from tableB where Column B = Column B from table 1?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM