基本连接查询理解

发布于 2024-09-01 02:20:10 字数 353 浏览 9 评论 0原文

我知道这很愚蠢,但是任何人都可以帮助我理解这个连接查询在详细描述中的作用吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走过海棠暮 2024-09-08 02:20:10

Left Joinj2.id IS NULL 结合仅返回 j1 的那些行,其中没有 j2 的行> 可以找到。

由于条件是j1.changedone < j2.changedone,它仅返回每个 trackid 具有最高 changedone 的行(如果有多个行具有该值 changedone< /code> 对于 trackid,它们都会被返回)。


因此,如果您有

trackid  changedone
      1           1
      1           2
      2           1

trackid  changedone
      1           2
      2           1

1 - 1 ,则 Left Join 会找到一条记录 (1 - 2),因此 j2 .idNOT NULL

The Left Join in combination with j2.id IS NULL returns only those rows of j1, where no row of j2 can be found.

Since the condition is j1.changedone < j2.changedone, it returns only the rows with the highest changedone per trackid (if there is more than one row with this value of changedone for a trackid, all of them are returned).


So if you have

trackid  changedone
      1           1
      1           2
      2           1

You will get

trackid  changedone
      1           2
      2           1

since for 1 - 1 the Left Join finds a record (1 - 2), so j2.id is NOT NULL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文