Dan
Dan

Reputation: 152

MySQL / PHP - Display all rows from table except one single row

me again!

So I'm wondering what the sequel/php code is to display all the rows in a table except one row. So display row 1, 2, 3 and 4 and every column, but don't display anything to do with row 5. The reason for this is I want to display all users in a user table except the user that is looking at the list itself.

Checking which user is looking at the list is fine because I can use a variable I set aside called userid which can be used to check it against. I just don't know the SQL terminology I need to use to essentially "select * from table except this row".

Any help please?

Upvotes: 0

Views: 3142

Answers (6)

Roshan
Roshan

Reputation: 16

SELECT *

FROM (SELECT ROW_NUMBER() 

OVER(ORDER BY id) RowNr, id FROM tbl) t

WHERE RowNr BETWEEN 10 AND 20

Upvotes: 0

vinayhudli
vinayhudli

Reputation: 119

$query = "SELECT * FROM users WHERE userId != $userId" ;

$userId can contain the user defined id

Upvotes: 1

Benvorth
Benvorth

Reputation: 7722

Why not just

 SELECT * FROM table WHERE userid != 'currentUser'

Upvotes: 1

Quazer
Quazer

Reputation: 383

SELECT * FROM table WHERE NOT user_id = < id >

Upvotes: 0

damian004
damian004

Reputation: 268

What's wrong with:

SELECT * FROM `table` WHERE `id` <> 5

Upvotes: 3

arik
arik

Reputation: 29250

SELECT * FROM `users` WHERE `userID` != 5

Replacing 5 with the current user's ID should do the trick.

Upvotes: 1

Related Questions