2

Consider having the ff. table (#temp_table)

id column1 column2
1 value1 mark
2 value2 jim
3 value3 taylor
4 value4 tess
5 value5 mark
6 value6 jim

How do I make a select query where first, I will exclude all rows where column2 = mark then exclude all rows where column2 = jim and column1 = value2

The expected result set should be

id column1 column2
3 value3 taylor
4 value4 tess
6 value6 jim

The query I have tried so far is

select * from #temp_table where column2 != 'mark' and (column2 !='jim' and column1 != 'value2') 

The result of my query

id column1 column2
3 value3 taylor
4 value4 tess
1
  • Don't do != --> <> ........ column2 <> 'mark' AND NOT (column2 ='jim' and column1 = 'value2') Commented Mar 29, 2023 at 4:43

1 Answer 1

1

You can "negate" a group of conditions using the operator NOT before the group

select * from #temp_table where column2 != 'mark' and NOT (column2 ='jim' and column1 = 'value2') 

More at: https://www.w3schools.com/sql/sql_and_or.asp

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.