1

how to select rows not in where company=c and leg=2 without specific DB function

+---------+-----+
| company | leg |
+---------+-----+
| c       |   1 |
| b       |   2 |
| c       |   2 |
| d       |   1 |
+---------+-----+

and get:

+---------+-----+
| company | leg |
+---------+-----+
| a       |   1 |
| b       |   2 |
| d       |   1 |
+---------+-----+

this is the typical wrong way:

SELECT *
FROM   mytable
WHERE  company <> 'c' AND leg <> 2
2
  • 1
    Where does company a come from in the result? It's not in your sample data? Commented Sep 12, 2018 at 5:44
  • Simply where not (company = 'c' and leg= 2)? Commented Sep 12, 2018 at 5:55

4 Answers 4

1

You could simply place these two conditions in the where clause:

SELECT *
FROM   mytable
WHERE  company <> 'c' OR leg <> 2
Sign up to request clarification or add additional context in comments.

Comments

0

You can try this -

select company, leg
from table-name
where company != 'c'
and leg != 2

Comments

0

you can use not in for company

SELECT *
FROM   mytable where company not in ('c') 

Comments

0

you can try this,

 select company,leg from mytable where company !='c' OR leg !=2;

result:

    +---------+-----+
    | company | leg |
    +---------+-----+
    | c       |   1 |
    | b       |   2 |
    | d       |   1 |
    +---------+-----+

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.