Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2008
    Posts
    13

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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    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 '%')

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •