1

I have a input table in mysql

 colA colB ------------ ABC -3 DEF 2 GHI -1 ABC 4 DEF -2 GHI -1 JKL 2 

and i want output as

 colA colB ------------ DEF 2 GHI -1 ABC 4 DEF -2 GHI -1 JKL 2 

i only want to exclude the negative values for colB for colA = 'ABC' and want to keep rest all the negative and positive values for colA in ('DEF','GHI','JKL')

3 Answers 3

3

You may try the following

SELECT colA, colB FROM my_table WHERE NOT (colA = 'ABC' and colB < 0) 

View Demo Fiddle

Let me know if this works for you.

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

Comments

0
SELECT colA, colB FROM table_name WHERE colB>=0 OR colA IN ('DEF','GHI','JKL'); 

Second solution

SELECT colA, colB FROM table_name WHERE colB>=0 OR colA!='ABC'; 

Comments

0

One of the ways to do it is by using an OR condition.

SELECT * FROM input_table WHERE colA <> 'ABC' or colB > 0; 

This query will return rows where any of the following conditions are true:

  • colA is different than "ABC"
  • colB is positive

If both conditions are false, it will not return that row.

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.