数据库查询未提取完整(或正确)信息

时间:2019-07-24 21:32:26

标签: mysql

我一直在进行多表查询(我没有很多经验),起初我以为它工作得很好,直到我注意到一半的结果都为空值。我将查询和表结构放在下面,因此将不胜感激!

SELECT
  i.name, i.material, i.price, a.str_mod, a.def_mod, 
  a.dex_mod, a.spd_mod, i.level_req 
FROM `character` as c 
LEFT JOIN item_owned as o ON c.uid = o.oid 
LEFT JOIN items as i ON o.iid = i.id 
LEFT JOIN armour as a ON i.id = a.aid 
WHERE uid = :id AND o.equipped = 1 AND i.type = 'Armour'

上面是我一直在运行的查询,下面是表结构 Armour talbe Items table Items Owned table

1 个答案:

答案 0 :(得分:0)

感谢Malfunct的不和谐,找到了解决方案...查询中有列错字,所以应该是

SELECT 
    i.name, i.material, i.price, a.str_mod, a.def_mod, a.dex_mod, a.spd_mod, i.level_req 
FROM `character` as c 
JOIN item_owned as o ON c.uid = o.oid 
JOIN items as i ON o.iid = i.id 
JOIN armour as a ON i.id = a.aid WHERE uid = 1 
AND o.equipped = 1 
AND i.type = 'Armour'