基本连接查询理解
我知道这很愚蠢,但是任何人都可以帮助我理解这个连接查询在详细描述中的作用吗?
SELECT j1.*
FROM jos_audittrail j1
LEFT OUTER JOIN jos_audittrail j2
ON (j1.trackid = j2.trackid AND j1.field = j2.field AND j1.changedone < j2.changedone)
WHERE j1.operation = 'UPDATE'
AND j1.trackid=$t_ids[$n]
AND j2.id IS NULL
我知道这很愚蠢,但我需要继续满足我的进一步需求...请帮助我...
I know this very silly, but can anybody help me in understanding what does this join query is doing in elabortive description?
SELECT j1.*
FROM jos_audittrail j1
LEFT OUTER JOIN jos_audittrail j2
ON (j1.trackid = j2.trackid AND j1.field = j2.field AND j1.changedone < j2.changedone)
WHERE j1.operation = 'UPDATE'
AND j1.trackid=$t_ids[$n]
AND j2.id IS NULL
I know its very silly, but i need to go ahead with my further need... Pls do help me...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Left Join
与j2.id IS NULL
结合仅返回j1
的那些行,其中没有j2
的行> 可以找到。由于条件是
j1.changedone < j2.changedone
,它仅返回每个trackid
具有最高changedone
的行(如果有多个行具有该值changedone< /code> 对于
trackid
,它们都会被返回)。因此,如果您有
1 - 1 ,则
Left Join
会找到一条记录 (1 - 2
),因此j2 .id
是NOT NULL
。The
Left Join
in combination withj2.id IS NULL
returns only those rows ofj1
, where no row ofj2
can be found.Since the condition is
j1.changedone < j2.changedone
, it returns only the rows with the highestchangedone
pertrackid
(if there is more than one row with this value ofchangedone
for atrackid
, all of them are returned).So if you have
You will get
since for
1 - 1
theLeft Join
finds a record (1 - 2
), soj2.id
isNOT NULL
.