SELECT * FROM USERS但不是我

时间:2018-06-11 18:11:59

标签: sql-server

我有一个表格,我用ids存储用户。如何获得所有用户,除了我的?我想我需要这样的东西:

SELECT * 
FROM USERS 
EXCEPT WHERE iduser = myiduser

1 个答案:

答案 0 :(得分:17)

SELECT * FROM USERS WHERE iduser != myiduser ;

或者这个:

    SELECT * FROM USERS 
    except
    select * from users
    WHERE iduser = myiduser ;

或者您可以创建视图

Create View Everyone_else
as
SELECT * FROM USERS WHERE iduser != myiduser ;

然后用

调用它
Select * from Everyone_else ;

您可能必须为myiduser使用撇号,如下所示:'myiduser'