Samir Akeb
Samir Akeb

Reputation: 37

Select all except one field in SQL

I would like to create a function which select all the characters with their properties in the db except the one who execute this function and because I'm new with SQL, I'm wondering if there was a way to do that : SELECT * FROM 'table name' EXCEPT 'the character executing the function'.

For example, if a player in a rpg game wants to attack someone, I would like to put the whole list of other players in the database that he can attacks. But if I do SELECT * FROM 'table name', he will be in the list and I don't want him to attack himself...

I search on Google and here but I only found solution for selecting all except a column, but i want that for a field.

Thanks for reading.

Upvotes: 0

Views: 3371

Answers (2)

Jonatan Cloutier
Jonatan Cloutier

Reputation: 929

You have to add a where clause:

SELECT * FROM 'tableName' WHERE characterId != 5

5 here being the ID from the character executing the function

Upvotes: 2

MH2K9
MH2K9

Reputation: 12039

I suggest you to use sub query. Get all names those are already executed the function & keep these name in NOT IN. For information keep a records for those name who executed the function. NOT IN example

SELECT * FROM table_name WHERE name NOT IN (
     SELECT name FROM table_name_where_executed_name_stored WHERE executed = 1
)

Upvotes: 2

Related Questions