MySQL内部查询
我们的产品适合多个品牌的一个或多个型号 我想生成一个适合单个产品的用户选择品牌的型号列表MySQL内部查询,mysql,Mysql,我们的产品适合多个品牌的一个或多个型号 我想生成一个适合单个产品的用户选择品牌的型号列表 SELECT ml.laser, pm.pistol_model_brand, pm.pistol_model_name FROM pistol_model as pm INNER JOIN model_laser as ml ON pm.pistol_model_id = ml.model_id WHERE pm.pistol_brand_id = :pistol_brand_id AND ml.lase
SELECT ml.laser, pm.pistol_model_brand, pm.pistol_model_name
FROM pistol_model as pm
INNER JOIN model_laser as ml
ON pm.pistol_model_id = ml.model_id
WHERE pm.pistol_brand_id = :pistol_brand_id AND ml.laser LIKE 'GTO%'
ORDER BY ml.laser
结果(3列)显示了我们的产品、品牌、型号。从这里我想,如果可能的话,生成一个适合我们产品的这些型号的列表
SELECT ml.laser, pm.pistol_model_brand, pm.pistol_model_name
FROM pistol_model as pm
INNER JOIN model_laser as ml
ON pm.pistol_model_id = ml.model_id
WHERE pm.pistol_brand_id = :pistol_brand_id AND ml.laser LIKE 'GTO%'
ORDER BY ml.laser
在挣扎了太多小时后,我不确定这是否可行,或者是否需要重建我的表
感谢您的帮助。谢谢。我建议您仔细检查第一个加入条件的逻辑。手枪型号id真的与激光型号id相同吗
SELECT
ml.laser
,pm.pistol_model_brand
,pm.pistol_model_name
FROM pistol_model as pm
INNER JOIN model_laser as ml
ON pm.pistol_model_id = ml.model_id
and pm.pistol_brand_id = ml.pistol_brand_id
WHERE
ml.laser LIKE 'GTO%'
ORDER BY
ml.laser
谢谢是的,它们是一样的。查询工作。我需要知道我是否能把所有的手枪模型和我们的激光模型匹配起来。