LeeKing
LeeKing

Reputation: 71

sql:select rows where two columns value

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

Upvotes: 1

Views: 56

Answers (4)

Mureinik
Mureinik

Reputation: 311018

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

SELECT *
FROM   mytable
WHERE  company <> 'c' OR leg <> 2

Upvotes: 1

Pratik Patel
Pratik Patel

Reputation: 353

you can try this,

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

result:

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

Upvotes: 0

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 32003

you can use not in for company

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

Upvotes: 0

Regressor
Regressor

Reputation: 1973

You can try this -

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

Upvotes: 0

Related Questions