使用 SQL 从不同的 table 获取仅在 Master table 中具有 ID 的名称?
get names from different tables only having id in Master table using SQL?
我有 4 个 table 用于填充具有 ID 和名称的组合框,它们的 ID 保存在主 table 现在我有 table 像:
product|id|name | brand |id|name color |id|name size|id|name
|1 |bottle| |2 |aqua| |4 |white| |1|large
让主要 table 仅存储他们的 ID 和它自己的 main_id。
问题:如何通过id获取产品名称、品牌、颜色、尺码?还有 main_id.
的总数
在查询中,我必须自己提供 id 才能获取名称:
select m.contr_num , m.contr_date , br.brand_name , bu.buyer_name ,
cl.colour_name , mn.manu_name , s.size_name from Scanning_M m inner join
Brand br on m.id = br.Brand_id,
你基本上已经有了,你只需要修复连接。您必须使用产品 ID m.product_id
和品牌 ID m.brand_id
等加入,而不是使用主要 table m.id
中的 ID 加入
(我猜测主要 table 中的 id 列与其他 table 的名称相同。)
SELECT m.contr_num , m.contr_date , br.brand_name , bu.buyer_name ,
cl.colour_name , mn.manu_name , s.size_name
FROM Scanning_M m
INNER JOIN Brand br ON m.Brand_id = br.Brand_id
INNER JOIN Buyer bu ON m.Buyer_id = bu.Buyer_id
INNER JOIN colour cl ON m.colour_id = cl.colour_id
INNER JOIN manu mn ON m.manu_id = mn.manu_id
INNER JOIN size s ON m.size_id = s.size_id
我有 4 个 table 用于填充具有 ID 和名称的组合框,它们的 ID 保存在主 table 现在我有 table 像:
product|id|name | brand |id|name color |id|name size|id|name
|1 |bottle| |2 |aqua| |4 |white| |1|large
让主要 table 仅存储他们的 ID 和它自己的 main_id。
问题:如何通过id获取产品名称、品牌、颜色、尺码?还有 main_id.
的总数在查询中,我必须自己提供 id 才能获取名称:
select m.contr_num , m.contr_date , br.brand_name , bu.buyer_name ,
cl.colour_name , mn.manu_name , s.size_name from Scanning_M m inner join
Brand br on m.id = br.Brand_id,
你基本上已经有了,你只需要修复连接。您必须使用产品 ID m.product_id
和品牌 ID m.brand_id
等加入,而不是使用主要 table m.id
中的 ID 加入
(我猜测主要 table 中的 id 列与其他 table 的名称相同。)
SELECT m.contr_num , m.contr_date , br.brand_name , bu.buyer_name ,
cl.colour_name , mn.manu_name , s.size_name
FROM Scanning_M m
INNER JOIN Brand br ON m.Brand_id = br.Brand_id
INNER JOIN Buyer bu ON m.Buyer_id = bu.Buyer_id
INNER JOIN colour cl ON m.colour_id = cl.colour_id
INNER JOIN manu mn ON m.manu_id = mn.manu_id
INNER JOIN size s ON m.size_id = s.size_id