Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2011
    Posts
    4

    Question Unanswered: Need help with select * from table_name where field=*

    Hi,

    i want to ask if it's possible to use * in a situation like this:

    Code:
    select * from table_name where field=*
    I'm talking about the where condition. Is there any way to select every value from a db column. I let you know that i cannot just put this field out of where because i want to field to become * if user don't input anything. I thought to use an if ... else.... but it will not suit me because i have to create a very confusing query.

    Please help me!!!!!

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    no, you cannot do anything like that

    what application language are you using? php?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    you can use wildcard characters in a where clause

    eg
    SELECT my, comma, separeted, column, list FROM mytable
    WHERE surname LIKE "pplas%"
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Jun 2011
    Posts
    4
    Quote Originally Posted by r937 View Post
    what application language are you using? php?
    yes i'm using php....

    Quote Originally Posted by healdem View Post
    you can use wildcard characters in a where clause
    i will try to use some wildcard characters and let you know...
    thanks for the help...!!!!!

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    use your php code to perform the following check --

    if the user submits something, let's say the value 'foo', just plug it into the following WHERE clause using an AND connector --
    Code:
    SELECT something
         , anything
         , just_not_the_dreaded_evil_select_star 
      FROM daTable
     WHERE 1 = 1
       AND somecolumn = 'foo'
    but if the user's submission is empty, which means the user wants all rows, the use php to construct your query without the AND condition --
    Code:
    SELECT something
         , anything
         , just_not_the_dreaded_evil_select_star 
      FROM daTable
     WHERE 1 = 1
    this will now return all rows

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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