简体   繁体   English

使用表2的外键和描述字段从表1检索数据

[英]Retrieve Data from Table1 using Table2's foreign key and description field

I can't explain it thoroughly in the title, but what I am trying to explain is: I have two tables a table for the assets and a table for the type of assets determined by the AssetCode. 我无法在标题中对其进行详细解释,但是我想解释的是:我有两个表,一个表用于资产,一个表用于由AssetCode确定的资产类型。 In the second table(AssetCode Table), there is the CodeID field, which is related to the AssetCode field in the first table (Assets Table), and the CodeDescription field which indicates the description of the code (eg laptop, chair, printer, etc.). 在第二个表(AssetCode表)中,有一个CodeID字段,它与第一个表(Assets Table)中的AssetCode字段有关,还有一个CodeDescription字段,它指示代码的描述(例如笔记本电脑,椅子,打印机,等等。)。 Is it possible to retrieve the data of the first table using the second table's CodeDescription field? 是否可以使用第二个表的CodeDescription字段检索第一个表的数据?

Try this. 尝试这个。

SELECT 
    t1.*
FROM
    Table1 t1,
    Table2 t2
WHERE
    t1.AssetCode = t2.CodeID
        AND t2.CodeDescription = 'chair';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用table1中的字段查找table2并从table2中检索列数据? - How to lookup table2 using a field in table1 and retrieve a column data from table2? 从表1中选择数据并将其复制到表2 - Select data from table1 and copy it to table2 如何使用Linq从table1检索所有列并从table2检索匹配的列(左外部联接) - How to retrieve all columns from table1 and matching columns from table2(Left outer join) using Linq 在 table1 中从 table2 的列派生的计算中添加列 - add column in table1 derived calculation from table2 's column 如果table1包含fk到table2的同一列的多个字段,如何从一个表创建多个外键到另一个表 - How to create multiple foreign keys from one table to another if table1 contains multiple fields with fk to the same column of table2 SQL查询以获取来自Table1和Table2的匹配记录,并使用自定义列显示1/0(如果存在数据) - SQL query to get matching records from Table1 and Table2 with a custom column showing 1/0 if data is present 使用SQL Server使用table2值更新table1 - Update of table1 with table2 values using SQL Server 在table1的指定列之后如何将table2的列连接到table1? - How to join column from table2 to table1 after a specified column of table1? 使用实体框架检索逗号分隔的外键表数据 - Retrieve comma separated foreign key table data using Entity Framework 使用表1主表(表2中的外键)显示Access数据库的表记录 - Display the table records of an Access database using table1 primary which is the foreign key in table 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM