在SQL中排除语句 [英] Exclude Statement in SQL

查看:3263
本文介绍了在SQL中排除语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用SQL语句从SQL数据库中排除数据?我的情况是我有一个用户登录到他们的个人资料页面,他们将能够朋友的人。

How to exclude data from an SQL database using an SQL statement? My situation is I have a user login to their profile page where they will be able to friend people. I want to display all users except themselves that are found in the SQL database.

推荐答案

也许只是

SELECT *
FROM 
    Users
WHERE
    UserId <> @ThisUserId

或使用区别联盟( EXCEPT SQL Server中的关键字,不确定其他RDBMS实现) / p>

Or using a Difference Union (The EXCEPT keyword in SQL Server, not sure about other RDBMS implementations)

SELECT *
FROM 
    Users

EXCEPT

SELECT *
FROM 
    Users
WHERE
    UserId = @ThisUserId

这篇关于在SQL中排除语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆