user213559
user213559

Reputation:

Conditional where clause in Mysql

How to use Conditional where clause in Mysql?

Select * from table where SubId='1' and null

Is it right? I want to display records with subId=1 and rows with subId null

Any suggestion...

Upvotes: 1

Views: 2032

Answers (2)

Daniel Vassallo
Daniel Vassallo

Reputation: 344301

This is what you need:

 SELECT * FROM table WHERE SubId='1' OR SubId IS NULL

Unfortunately in English language, AND and OR can be used interchangeably in certain cases:

  • "I always carry an umbrella for when it rains and snows."
  • "I always carry an umbrella for when it rains or snows."

This is probably why you were trying to build your query with an 'AND'. You may want to check the following Wikipedia article for further information about this problem:

Upvotes: 7

Related Questions