How to exclude a specific entry in SQL?

I want to exclude an entry in my table, but it does not work logically. Here is my table Weapons:

Name / DPS / Style

Noxious Bow / 1000 / Range
Chaotic Staff / 800 / Magic
Armadyl Crossbow / 750 / Range
Saradomin Godsword / 600 / Melee
Dragon Longsword / 600 / Magic
Dragon Longsword / 550 / Melee
Elder Shortbow / 500 / Range

What I'm trying to do is exclude a record Dragon Longswordthat has Styleof Melee.

Here is what I tried:

SELECT *
FROM Weapons
Where Name!='Dragon Longsword' AND Style!='Melee';

What happens is that it does not display a record containing Dragon Longswordor Melee. I want it to not display only the following entry:

Dragon Longsword / 550 / Melee
+4
source share
2 answers

Logically what you want:

not (name == 'Dragon Longsword' and Style == 'Melee')

Using simple logic ( De Morgan's laws , thanks @Rocket), this can be translated into:

name != 'Dragon Longsword' or Style != 'Melee'

, OR, AND, , :

SELECT *
FROM Weapons
Where Name!='Dragon Longsword' OR Style!='Melee';
+9
SELECT * 
FROM Weapons 
Where Name!='Dragon Longsword' OR Style!='Melee'
+2

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


All Articles