多个 MySQL 嵌套选择

发布于 2024-12-12 13:45:42 字数 678 浏览 0 评论 0原文

你好,我想知道是否有人可以帮忙,我完全精神障碍。

我有一个完美运行的 select 语句,但是我现在想对照另一个表检查结果(名字和姓氏),以了解有关它们的更多详细信息。我一辈子都不知道该怎么做。

SELECT `FirstName` ,  `Surname` , MobilePhone
FROM users
WHERE NOT 
EXISTS (

SELECT PhoneNumber
FROM Orangedata
WHERE users.MobilePhone = orangedata.`PhoneNumber`
)

此选择返回我想要运行另一个选择的记录列表(姓名和手机)。

结果看起来像

FirstName Surname Mobile

我想运行我的下一个选择,它说

Select *
from Table 3
WHERE FirstName = FirstName from previous select AND WHERE Surname = Surname from previous select.

我正在寻找的总体结果是

为在表 Orangedata 中没有任何记录的用户提供所有详细信息(来自表 3)

它实际上是三个嵌套选择(我想)但我就是想不出来

Hi there I wonder if someone could help, I am having a complete mental block.

I have this select statment that works perfectly, however I now want to check the results (FirstName and Surname) against another table to find out more details about them. I can't for the life of me figure how to do that.

SELECT `FirstName` ,  `Surname` , MobilePhone
FROM users
WHERE NOT 
EXISTS (

SELECT PhoneNumber
FROM Orangedata
WHERE users.MobilePhone = orangedata.`PhoneNumber`
)

This select returns me a list of records (Name and Mobiles) that I want to run another select with.

The Result looks like

FirstName Surname Mobile

I want to run my next Select that says

Select *
from Table 3
WHERE FirstName = FirstName from previous select AND WHERE Surname = Surname from previous select.

The overall result I am looking for is

Give me all the details (from Table 3) for a user that does not have any record in table Orangedata

Its effectively three nested selects (I think) and I just can't figure it out

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

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

发布评论

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

评论(1

情深已缘浅 2024-12-19 13:45:42
SELECT table3.* FROM    
      table3 
      JOIN 
      (SELECT `FirstName` ,  `Surname` , MobilePhone
      FROM users
      WHERE NOT 
      EXISTS (
           SELECT PhoneNumber
           FROM Orangedata
           WHERE users.MobilePhone = orangedata.`PhoneNumber`
      )) as b  
ON (table3.FirstName = b.FirstName AND table3.Surname = b.Surname))

或者像这样的东西

SELECT table3.* FROM    
      table3 
      JOIN 
      (SELECT `FirstName` ,  `Surname` , MobilePhone
      FROM users
      WHERE NOT 
      EXISTS (
           SELECT PhoneNumber
           FROM Orangedata
           WHERE users.MobilePhone = orangedata.`PhoneNumber`
      )) as b  
ON (table3.FirstName = b.FirstName AND table3.Surname = b.Surname))

Or something like this

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