简体   繁体   中英

How to make a sub-query based on query results in SQL

I'm currently trying to query a list of our assembly items, along with their corresponding components. I've been trying this query a few different ways, here is where I'm currently at (closest I've gotten)

SELECT inv_mast.item_id AS [Item ID]
    ,inv_mast.item_desc AS [Item Description]
    ,IMC.item_id AS [Component Item ID]
FROM inv_mast
INNER JOIN assembly_line ON inv_mast.inv_mast_uid = assembly_line.inv_mast_uid
LEFT JOIN inv_mast IMC ON assembly_line.component_inv_mast_uid = inv_mast.inv_mast_uid
WHERE inv_mast.item_id = 'LFV-SV59Z-2ZGD-LOGO-L'

In the "Assembly_line" table there is a Component_inv_mast_uid which I need to use to query our Item ID's for the components (inv_mast joins to assembly_line on the inv_mast_uid)

It should export something like this:

LFV-SV59Z-2ZGD-LOGO-L (LFV-SV59Z-2ZGD-L)

LFV-SV59Z-2ZGD-LOGO-L (Print Fee)

I forgot to mention what is currently exporting. When I run this query, it provides most information correct, however the "Component Item ID" column is returning Null, and I'm not sure why. I've only had experience so far with joining basic tables, so subqueries are very new to me.

try to use

WHERE inv_mast.item_id like 'LFV-SV59Z-2ZGD-LOGO-L%'

instead of = 'LFV-SV59Z-2ZGD-LOGO-L'

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