这是一个脏/不符合左连接? [英] is this a dirty / not conform left join?
问题描述
我需要为表格TBL_B中的每条记录处理某事,以获取来自例如另一个查询的每个结果行。 TBL_A:
I need to process "something" for each record in a table TBL_B for every result line from another query from e.g. TBL_A:
SELECT
*
FROM TBL_A
LEFT JOIN TBL_B ON '1' = '1' // is this really clean??
WHERE TBL_A.ID <does match a condition>
这两个表没有任何主 - 外关系。一切正常。我唯一担心的是,标记为LEFT JOIN(与interbase一起使用)的粗体仅仅是偶然的。
我的问题:这种LEFT JOIN SQL是否兼容?
提前谢谢。
布鲁诺
NB 0:相反左连接我尝试了FROM TBL_A,TBL_B,这没有达到预期的结果(这对我来说不清楚为什么不......)
NB 1:是的,我知道,SELECT *并不好。我写这篇文章只是为了让问题简短;)
N.B. 2:将Q& A列表中的主题与您在打开问题时看到的内容进行比较。工作中的偏执狂程序员* lol *
The two tables do not have any Primary-Foreign relation. Everything works fine. My only concern is, that the bold marked LEFT JOIN (which works with interbase) does only work by chance.
My question: Is this kind of LEFT JOIN SQL compliant?
Thank you in advance.
Bruno
N.B. 0: Instead left join I tried "FROM TBL_A,TBL_B" which did not result in the expected result (and which is not clear for me why not....)
N.B. 1: And yes I know, SELECT * is not good. I wrote it only to make the question short ;)
N.B. 2: Compare subject in Q&A list against what you see when you open the question. Paranoia programmers at work *lol*
推荐答案
因为'1'='1'是一个完全有效的where子句,这是一个有效的LEFT JOIN并且有效。
实际上这是写一个CROSS JOIN的一种方式......
http://www.w3resource.com/sql/joins/cross-join.php [ ^ ]
As '1' = '1' is a perfectly valid where clause, this is a valid LEFT JOIN and works.
In fact this is one way to write a CROSS JOIN...
http://www.w3resource.com/sql/joins/cross-join.php[^]
Bruno,请看这里: SQL连接的可视化表示 [ ^ ]。我想它可能会帮助你理解连接是如何工作的。
Kornfeld是对的,它的意思是交叉加入 [ ^ ],因为使用1 = 1
类似于:
Bruno, please have a look here: Visual Representation of SQL Joins[^]. I think it might help you to understand how joins works.
Kornfeld is right, it means cross join[^], because using1=1
is similar to:
SELECT t1.*, t2.*
FROM t1, t2
这意味着参与加入的表格的笛卡尔积。
LEFT,RIGHT或INNER JOIN意味着:
which means Cartesian product of the tables involved in the join.
LEFT, RIGHT or INNER JOIN means this:
WHERE t1.PK = t2.FK
顺便说一句 1 = 1
总是返回 true
。这是提供sql注入攻击的最简单方法;)
你可以通过这篇文章解决一些挫折:
为什么使用WHERE 1或WHERE 1 = 1? [ ^ ]
加入1 = 1与交叉加入 [ ^ ]
我不知道怎么解释得更好。如果您有任何其他问题......
By The Way 1=1
always returns true
. It's the simplest way to provide sql injection attack ;)
Some frustration you can solve with this articles:
Why use WHERE 1 or WHERE 1=1?[^]
Join on 1=1 versus cross join[^]
I don't know how to explain it better. If you have any other question...
这篇关于这是一个脏/不符合左连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!