mysql 不在或 value=0?

发布于 2024-08-15 08:12:44 字数 494 浏览 5 评论 0原文

数据库之一称为小部件,它有“id”和“title”。数据库二称为 widget-layouts,它具有“module-id”、“widget-id”、“position”和“weight”。

我想做的是检查 widgets.id 是否存在于 widget-layout.widget-id 中,如果存在,则 widget-layouts.position = 0 。我还想获取不存在的 widgets 的值不存在于小部件布局中。

这是我一直在使用的 mysql 查询。

从小部件、小部件布局中选择 * WHERE (widge-layouts.position = '0' AND widgets.id = widget-layouts.widget-id) 或 widgets.id 不在(选择 * FROM 小部件布局)

通过这个查询,我得到了一个巨大的小部件列表,其中每个小部件都显示多次。

对此有什么想法吗?

Database one is called widgets, it has "id" and "title". Database two is called widget-layouts and it has "module-id", "widget-id", "position", and "weight".

What I am trying to do is check to see if widgets.id exists in widget-layout.widget-id and if it does, then does widget-layouts.position = 0. I also want to get the values of widgets that don't exist in widget-layouts.

Here is the mysql query I have been working with.

SELECT * FROM widgets, widget-layouts
WHERE (widge-layouts.position = '0'
AND widgets.id =
widget-layouts.widget-id) OR
widgets.id NOT IN (SELECT * FROM
widget-layouts)

With this query I am getting a huge list of widgets where each widget is displayed multiple times.

Any ideas about this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

五里雾 2024-08-22 08:12:44
 SELECT *
 FROM widgets AS w
     LEFT JOIN widget-layouts AS wl
         ON w.id = wl.widget-id
 WHERE wl.widget-id IS NULL
     OR wl.position = '0'      
 SELECT *
 FROM widgets AS w
     LEFT JOIN widget-layouts AS wl
         ON w.id = wl.widget-id
 WHERE wl.widget-id IS NULL
     OR wl.position = '0'      
从﹋此江山别 2024-08-22 08:12:44
SELECT * FROM widgets LEFT JOIN widget-layouts on widget-id = id WHERE position = 0

应该显示那些存在并且位置 = 0 的内容

SELECT * FROM widgets RIGHT JOIN widget-layouts on id = widget-id where id is NULL

应该显示那些仅存在于小部件布局中的内容

SELECT * FROM widgets LEFT JOIN widget-layouts on widget-id = id WHERE position = 0

should show those that exist and have position = 0

SELECT * FROM widgets RIGHT JOIN widget-layouts on id = widget-id where id is NULL

should show those that exist in widget-layouts only

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