If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How to Ignore Where clause

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-07-10, 02:56
gompuok gompuok is offline
Registered User
 
Join Date: Oct 2008
Posts: 12
How to Ignore Where clause

Hi, It's me again.
I have a simple question which I cant figure out how to do it. Let say I have to pass a parameter called name to my sql query that looks like below;

Select * from users where name = ${name}

What i want is, If there is a name value passes, apply it, if not, return all the name (no filter).

Hope anyone can help me. Thank you very much in advance.
Reply With Quote
  #2 (permalink)  
Old 06-07-10, 07:41
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by gompuok View Post
What i want is, If there is a name value passes, apply it, if not, return all the name (no filter).
this is real easy, and it's not a mysql question

if there is a name value passed in, run this --
Code:
SELECT columns FROM users WHERE name = ${name}
if there is no name value passed in, run this --
Code:
SELECT columns FROM users
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 06-18-10, 07:16
sathkum2281 sathkum2281 is offline
Registered User
 
Join Date: Jun 2010
Posts: 4
can try this, this will solve your problem.
SELECT * FROM users where if(LENGTH('${name}')>0,name = '${name}',name like '%')
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On