简体   繁体   中英

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. 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.). Is it possible to retrieve the data of the first table using the second table's CodeDescription field?

Try this.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM