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 > Need help with select * from table_name where field=*

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-13-11, 12:27
pplastiras pplastiras is offline
Registered User
 
Join Date: Jun 2011
Posts: 4
Question 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!!!!!
Reply With Quote
  #2 (permalink)  
Old 07-13-11, 13:03
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
no, you cannot do anything like that

what application language are you using? php?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 07-13-11, 14:25
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
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 my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #4 (permalink)  
Old 07-13-11, 15:07
pplastiras pplastiras is offline
Registered User
 
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...!!!!!
Reply With Quote
  #5 (permalink)  
Old 07-13-11, 15:26
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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