views:

392

answers:

2

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...

+5  A: 

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:

Daniel Vassallo