Amandeep Singh Amandeep Singh - 4 days ago 5
MySQL Question

Getting all results using where clause

I have a function which takes an argument that is used in where clause

function(string x)-->Now this will create a sql query which gives

select colname from tablename where columnname=x;


Now I want this function to give all rows i.e. query equivalent to

select colname from tablename;


when I pass x="All".

I want to create a generic query that when I pass "All" then it should return me all the rows else filter my result.

Answer

Just leave the where condition out.

If you really want it that complicated use

where columnname LIKE '%'

which will only filter nulls.

Comments