这个 MySQL 语句有什么作用?
INSERT IGNORE INTO `PREFIX_tab_lang` (`id_tab`, `id_lang`, `name`)
(SELECT `id_tab`, id_lang, (SELECT tl.`name`
FROM `PREFIX_tab_lang` tl
WHERE tl.`id_lang` = (SELECT c.`value`
FROM `PREFIX_configuration` c
WHERE c.`name` = 'PS_LANG_DEFAULT' LIMIT 1) AND tl.`id_tab`=`PREFIX_tab`.`id_tab`)
FROM `PREFIX_lang` CROSS JOIN `PREFIX_tab`);
它来自开源项目,没有可用的文档。
特别是,cross-join
是什么意思?我只使用过 join/left join 。
INSERT IGNORE INTO `PREFIX_tab_lang` (`id_tab`, `id_lang`, `name`)
(SELECT `id_tab`, id_lang, (SELECT tl.`name`
FROM `PREFIX_tab_lang` tl
WHERE tl.`id_lang` = (SELECT c.`value`
FROM `PREFIX_configuration` c
WHERE c.`name` = 'PS_LANG_DEFAULT' LIMIT 1) AND tl.`id_tab`=`PREFIX_tab`.`id_tab`)
FROM `PREFIX_lang` CROSS JOIN `PREFIX_tab`);
It's from an opensource project,and no documentation available.
Especially,what does cross-join
mean? I've only used join/left join .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 MySQL 文档,它基本上是 < code>INNER JOIN,并且
INNER JOIN
与JOIN
相同(即“INNER
”是默认值) 。According to the MySQL documentation, it's basically a synonym for
INNER JOIN
, andINNER JOIN
is the same as justJOIN
(that is, "INNER
" is the default).交叉连接: http://en.wikipedia.org/wiki/Join_% 28SQL%29#Cross_join
查询将选择结果插入到
PREFIX_tab_lang
中。选择的只是叉积中的两列。第三列——名称——实际上来自一个完全不同的选择,这也非常简单,只是其中一个where
条件是另一个选择。简而言之,这是我见过的最糟糕的查询之一。它的性能可能很糟糕,应该用一些受 TRANSATION 保护的代码或至少一个存储过程来替换它。
Cross-join: http://en.wikipedia.org/wiki/Join_%28SQL%29#Cross_join
The query inserts into
PREFIX_tab_lang
the results of a select. The select is just two columns from the cross-product. The third column -- name -- actually comes from a totally different select, which is also pretty straight-forward except that one of it'swhere
conditions is yet another select.In short, this is one of the worst queries I've ever seen. It's preformance is probably horrible, and it should be replaced by a bit of TRANSATION-protected code or, at the very least, a stored procedure.
您实际上可以将以下查询视为 MySQL 中的同义词:
测试用例:
所有四个查询都将返回以下结果集:
You can actually consider the following queries to be synonyms in MySQL:
Test Case:
All four queries would return the following result set: