对抗 INNER JOINS - 章节:未知专栏
SELECT p.id
FROM produkty p, przyporzadkowania pr, stany_magazynowe, gk_grupy_produkty
INNER JOIN sub_subkategorie ssi
ON pr.sub_subkategorie_id = ssi.ID
表及其重要字段
produkty - id, pozycja
przyporzadkowania - id, produkt_id, sub_kategoria_id, sub_subkategoria_id
sub_subkategorie - id, subkategorie_id, pozycja
subkategorie - id, kategorie_id, pozycja
kategorie - id, pozycja
错误“#1054 - 'on 子句'中的未知列 'pr.sub_subkategorie_id'”
尝试过,
SELECT p.id, pr.sub_subkategorie_id
结果相同。
完整查询(由于上述查询失败而未测试):
SELECT p.id
FROM produkty p, przyporzadkowania pr, stany_magazynowe, gk_grupy_produkty
INNER JOIN sub_subkategorie ssi ON pr.sub_subkategorie_id = ssi.ID
INNER JOIN subkategorie si ON ssi.subkategorie_id = si.id
INNER JOIN kategorie c ON si.kategorie_id = c.id
WHERE stany_magazynowe.produkty_id = p.id
AND p.id = pr.produkty_id
AND pr.sub_subkategorie_id =1
AND p.widoczny = '1'
AND p.id = gk_grupy_produkty.id_produktu
AND gk_grupy_produkty.id_grupy =1
AND gk_grupy_produkty.towar_widocznosc =1
AND c.id = '1'
ORDER BY c.pozycja, si.pozycja, ssi.pozycja, p.pozycja
希望我提供了足够的信息(之前的问题 - SELECT * FROM table WHERE field IN (SELECT id FROM table ORDER BY field2))
编辑:
是的,有拼写错误,但仅在这里,在 stackoverflow 上(咖啡太多了,我的手指在飞)。谢谢大家,你们拯救了我的一天!
SELECT p.id
FROM produkty p, przyporzadkowania pr, stany_magazynowe, gk_grupy_produkty
INNER JOIN sub_subkategorie ssi
ON pr.sub_subkategorie_id = ssi.ID
Tables and their important fields
produkty - id, pozycja
przyporzadkowania - id, produkt_id, sub_kategoria_id, sub_subkategoria_id
sub_subkategorie - id, subkategorie_id, pozycja
subkategorie - id, kategorie_id, pozycja
kategorie - id, pozycja
Error "#1054 - Unknown column 'pr.sub_subkategorie_id' in 'on clause'"
Tried with
SELECT p.id, pr.sub_subkategorie_id
Same result.
Full query (not tested due to failure of query above):
SELECT p.id
FROM produkty p, przyporzadkowania pr, stany_magazynowe, gk_grupy_produkty
INNER JOIN sub_subkategorie ssi ON pr.sub_subkategorie_id = ssi.ID
INNER JOIN subkategorie si ON ssi.subkategorie_id = si.id
INNER JOIN kategorie c ON si.kategorie_id = c.id
WHERE stany_magazynowe.produkty_id = p.id
AND p.id = pr.produkty_id
AND pr.sub_subkategorie_id =1
AND p.widoczny = '1'
AND p.id = gk_grupy_produkty.id_produktu
AND gk_grupy_produkty.id_grupy =1
AND gk_grupy_produkty.towar_widocznosc =1
AND c.id = '1'
ORDER BY c.pozycja, si.pozycja, ssi.pozycja, p.pozycja
Hope that I gave enough info (earlier question - SELECT * FROM table WHERE field IN (SELECT id FROM table ORDER BY field2))
EDIT:
Yes, there is typo, but only here, on stackoverflow (too much coffee, my fingers are flying). Thank you all, You saved my day!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您以错误的顺序连接表:
该错误是由于
JOIN
关键字的优先级高于逗号造成的。像这样的错误是我敦促您不要使用带有逗号的隐式连接语法,而是始终使用 JOIN 关键字显式编写连接的原因之一。以下是使用显式连接重写的完整查询:
相关问题
You're joining the tables in the wrong order:
The error is due to the higher precedence of the
JOIN
keyword compared to the comma. Errors like this are one of the reasons why I would urge you not to use the implicit join syntax with the comma and instead always write your joins explicitly using the JOIN keyword.Here is your complete query rewritten using explicit joins:
Related question
您将“经典”连接与
join
关键字混合在一起。您应该对所有连接使用join
关键字。该错误来自于您正在加入
gk_grupy_produkty
表,其中该字段不存在。数据库实际上将您的查询视为:您应该使用:
You are mixing "classical" joins with the
join
keyword. You should use thejoin
keyword for all the joins.The error comes from that you are joining on the
gk_grupy_produkty
table, where that field doesn't exist. The database really looks at your query as:You should use:
名为
sub_subkategoria_id
的列是否有拼写错误?Is the column named
sub_subkategoria_id
a typo?以此开始:(填写???)
(您不需要指定INNER)
您的原始FROM子句:
有表p和pr,没有指定JOIN条件,这将导致笛卡尔积或交叉联接(在这种情况下可能不是一件好事)以及查询中其他任何地方都没有引用的表:
指定 JOIN
并删除
提示:如果您没有在 SELECT、ORDER BY、GROUP BY、WHERE 中引用表中的任何列,则该表可能不属于您的 FROM 子句。 (除非它是联接/联结表。)
Start with this: (fill in the ???)
(You don't need to specify INNER)
Your original FROM clause:
Has tables p and pr for which no JOIN condition is specified which will result in a cartesian product or cross join (probably not a good thing in this case) as well as tables that aren't referenced anywhere else in your query:
Specify a JOIN for
and remove
Hint: If you do not reference any columns from a table in your SELECT, ORDER BY, GROUP BY, WHERE then the table probably does not belong in your FROM clause. (Unless it's a join/junction table.)