简体   繁体   English

无法使用我的SQL查询访问表。 没有得到理想的结果

[英]Having trouble accessing a table with my SQL query. Not getting the desired result

I'm having trouble displaying setid's from the table 'sets' with my SQL query. 我在用SQL查询显示“集合”表中的setid时遇到问题。 I'm only receiving setid's from 'inventory', not from 'sets'. 我仅从“库存”接收setid,而不从“集合”接收setid。

$setidquery = "SELECT inventory.itemid,
                        inventory.setid,
                        inventory.colorid,
                        inventory.itemtypeid,
                        colors.colorname,
                        parts.partname,
                        parts.partid,
                        sets.setid
                        FROM inventory
                        JOIN parts ON inventory.itemid = parts.partid
                        JOIN colors ON inventory.colorid = colors.colorid
                        JOIN sets ON sets.SetID = inventory.SetID
                        WHERE sets.setid = '$_COOKIE[setid]'
                        ORDER BY partname ASC
                        LIMIT 1000";

'$_COOKIE[setid]' is a search from a previous stage, so as you can probably guess, that will be the specific 'SetID'. “ $ _COOKIE [setid]”是上一阶段的搜索,因此您可能会猜到,这将是特定的“ SetID”。 But when enter a setid from the table sets, nothing shows up. 但是,当从表集中输入setid时,没有任何显示。

For example the set 375-2 shows up fine, because that set is in the table inventory, but the set 0011-2 does not show up, because that one is in the table sets. 例如,集合375-2显示得很好,因为该集合在表清单中,但是集合0011-2没有显示,因为那个在表集合中。

Database scheme: http://weber.itn.liu.se/~stegu76/TNMK30-2016/legodatabasen.pdf 数据库方案: http : //weber.itn.liu.se/~stegu76/TNMK30-2016/legodatabasen.pdf

Goal: To print a table with sets from both inventory and sets. 目标:打印一个包含库存和库存集的表格。

Sorry for repeating myself a lot, just trying to be specific. 很抱歉重复很多次,只是想说清楚一点。

If you use JOIN it only get's the records where sets.SetID = inventory.SetID match. 如果使用JOIN,则仅获得set.SetID = ventory.SetID匹配的记录。 If you only have a record in the table sets and not in inventory the records don't match with your join. 如果表集中只有一条记录,而清单中没有,则该记录与您的联接不匹配。 You probably need to use RIGHT JOIN to also show records that don't have matching results with the Inventory table. 您可能需要使用RIGHT JOIN来显示与Inventory表没有匹配结果的记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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