【问题标题】:Sql Request? Where clauseSql 请求? Where 子句
【发布时间】:2016-10-21 10:51:29
【问题描述】:

首先,对不起我的英语,我来自法国。

我尝试发出一个简单的 SQL 请求,但我被卡住了,我不知道为什么。所以这里是我想要做的简化:

2 个表格:

user_profile: iduser , idprofil

配置文件:idprofil,配置文件

我想要什么:

我想获取一个用户没有的配置文件列表。因此,如果用户在 user_profil 中有配置文件,我不希望在请求的结果中包含此配置文件。

事实上,如果用户有配置文件,我不希望这个配置文件出现在请求的结果中。

我试过了:

select distinct (p.idprofil), p.profil 
from profil p, user_profil u
where p.idprofil != u.idprofil and u.iduser = X

但它不起作用(如果用户只有一个配置文件,它可以工作,但如果他至少有 2 个配置文件,它就不起作用。)

【问题讨论】:

    标签: mysql database select


    【解决方案1】:

    使用not innot exists

    select u.*
    from user_profil u
    where u.idprofil not in (select p.idprofil from profil p);
    

    【讨论】:

    • 完美运行!!!谢谢 :) 我的要求:选择 p.idprofil,p.profil from profil p where p.idprofil not in (select u.idprofil from user_profil u where u.iduser =X)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-02
    • 1970-01-01
    • 1970-01-01
    • 2023-02-24
    • 2014-10-30
    • 2023-03-31
    相关资源
    最近更新 更多