0

I tried to write a query that would return each of the 1 matkul values worth E with conditions on the matkul value not having a value of A, AB, B, BC, C, D.

ID id_matkul nilai
1 a101 E
2 a101 E
3 a102 A
4 a102 E
5 a102 E
6 a103 BC
7 a103 E
8 a104 B
9 a104 E
10 a104 E
PM 77-1
  • 12,933
  • 21
  • 68
  • 111

1 Answers1

0

In order to perform a conditional query you can use the SQL NOT operator. In this example where you have multiple conditionals that must be satisfied it may make more sense to use the NOT IN operator with a list of values that must be satisfied.

Examples

NOT

SELECT * FROM table WHERE NOT id = 'A' AND NOT id = 'B';

More examples - W3Schools

NOT IN

SELECT * FROM table WHERE id NOT IN ('A', 'B');

More examples - W3Resource

Also if depending on how you determined which values you need to exclude (if you query to find them for example) you can either nest the Not In with a query or take a look at this stack overflow solution - Not-in-vs-Not-Exists

Stu
  • 30,392
  • 6
  • 14
  • 33
Colin McCormack
  • 137
  • 1
  • 7