mysql condition inside IN clause

Hi I am writing mysql/oracle database query to support select all for in clause my query goes something like this

SELECT * FROM country
country_id in( IF('test' = 'test',(1,2,3),true) )

If condition ('test' = 'test') is true then it should fire query like

SELECT * FROM country WHERE  country_id in(1,2,3)

Else it should fire query

 SELECT * FROM country WHERE  country_id in(true)


You can use test as variable here, if test1 = test2 then country_id will be in (1,2,3) else there will be no limited for country_id:

SELECT * FROM country
WHERE ((test1 = test2 and country_id in(1,2,3))or
        test1 <> test2)

You can do this with basic boolean logic. What you are doing is equivalent to:

FROM country
WHERE country_id in (1,2,3) or 'test' <> 'test';

(Note: I am not testing for NULL on 'test' because it is a literal value. If this is really a variable that can take on a NULL value, you would have to take that into account as well.)

Need Your Help

bootstrap: change modal backdrop opacity only for specific modals

javascript jquery css jquery-plugins twitter-bootstrap

I have a menu with multiple modals. When I open one over another it turns backgrount into black, which is ugly.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.