Exclude SQL statement

How to exclude data from SQL database using SQL statement? My situation is that I have a user login on my profile page, where they can communicate with each other. I want to show all users, except themselves, who are in the SQL database.

+3
source share
5 answers

Maybe just

SELECT *
FROM 
    Users
WHERE
    UserId <> @ThisUserId

Or using delta union ( EXCEPTkeyword in SQL Server, not sure about other RDBMS implementations)

SELECT *
FROM 
    Users

EXCEPT

SELECT *
FROM 
    Users
WHERE
    UserId = @ThisUserId
+8
source

What about:

SELECT * FROM people WHERE person_id != $current_user_id
+5
source

, , .

, , , , ( " " ), .

, , , , , , . - , . , ...

, .

, , "Email" "UnwantedEmail", "". , , "Email", "UnwantedEmail", :

SELECT Email.Address FROM UnwantedEmail
RIGHT JOIN Email ON UnwantedEmail.Address=Email.Address
WHERE UnwantedEmail.Address Is Null;

: -)

/

+3
source
select * from Foo where UserName not in ('Rohan', 'Rohan friend', .....)

This is useful?

+2
source

If you know what a unique user ID is, you can use something like this, for example:

SELECT * FROM usertable WHERE id!='myuserid'

What I am doing with one of my authentication scripts is to store information for the person who is currently logging into the system in a variable, so in PHP it will look like this:

SELECT * FROM usertable WHERE id!='check(id)'
0
source

Source: https://habr.com/ru/post/1722206/


All Articles