Dio Satria Darma
Dio Satria Darma

Reputation: 17

sql,how to select fields with 2 conditions

how to choose a field with conditions: 1. not null & 2. id = 1 in the same field?

Upvotes: 0

Views: 48

Answers (3)

StackUser
StackUser

Reputation: 426

You can try IS NOT NULL

SELECT column1,column2
FROM tablename
WHERE id IS NOT NULL AND id=1;

Upvotes: 1

Mayank Porwal
Mayank Porwal

Reputation: 34046

If you just want records with id=1, then the condition id is NOT NULL is superflous. You can just write:

SELECT * 
FROM table
WHERE id = 1;

If you want records with id is NOT NULL then id=1 becomes superflous. You can do:

SELECT * 
FROM table
WHERE id is NOT NULL;

Upvotes: 1

Nikhil
Nikhil

Reputation: 3950

where id is not null or id=1;  ...  

Upvotes: 1

Related Questions