Pacijent Pacijent - 5 months ago 6
SQL Question

SELECT columns EXCEPT values that are loaded from file

Let's say i have table

Table1
:

|Column1|Column2|Column3|
|1 |25 |a |
|2 |48 |a |
|3 |25 |b |
|4 |25 |d |
|5 |16 |e |


And i have command:

"SELECT Column1 FROM TABLE1 WHERE Column2 = 25)";


So now output is:

1
3
4


Now i want to do the same but if column3 = a, then do not select that row, so output is now:

3
4


And now i want A to be loaded from txt file, but in that file would be more values (a, b, d, g, u...)

So basicly i want to

SELECT [columns] FROM [table] WHERE [column1] = 1 EXCEPT [column2] = [values from txt]


I just need logic for command, i know everything other.

Answer

Add AND [column2] NOT IN [values from txt]:

SELECT [columns] FROM [table]
WHERE [column1] = 1 AND [column2] NOT IN  (a, b, d, g, u...)
Comments