简体   繁体   English

SQL请求? Where子句

[英]Sql Request? Where clause

First of all, sorry for my english, I'm from france. 首先,对不起我的英语,我来自法国。

I try to make a simple SQL request, but I'm stucked, and I don't know why. 我尝试提出一个简单的SQL请求,但遇到问题,我也不知道为什么。 So here are a simplification of what I want to do: 所以这是我想要做的一个简化:

2 tables: 2张桌子:

user_profil: iduser , idprofil user_profil:iduser,idprofil

profil : idprofil, profil 配置文件:idprofil,profil

What I want: 我想要的是:

I'd like to get the list of the profils which one user don't have. 我想获取一个用户没有的配置文件列表。 So if a user have a profil in user_profil, I don't want to have this profil in the result of the request. 因此,如果用户在user_profil中有一个配置文件,我不想在请求结果中包含该配置文件。

Infact, if the user have the profil, I don't want this profil to be in the result of the request. 实际上,如果用户具有配置文件,则我不希望该配置文件出现在请求的结果中。

I tried: 我试过了:

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

But it doesn't work (it works if a user have only one profil, but if he has at least 2 profils, it doesn't work.) 但这是行不通的(如果用户只有一个配置文件,则有效;但如果用户至少有2个配置文件,则行不通。)

Use not in or not exists : 使用not innot exists

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM