Simple query question...

Results 1 to 3 of 3

Thread: Simple query question...

  1. #1
    Join Date
    Dec 1969

    Default Simple query question...

    Hey, I was wondering how to address the term, when using sql seleect statement, for the column name.<BR><BR>Not saying query where I KNOW the columnname, just the basic word to explain any columnname. It&#039;s hard to explain. here&#039;s an ex:<BR><BR>Table: TEST<BR>3 columns<BR><BR>Name &#124 Email &#124 Address<BR>blah blah blah<BR>(Blah are the records per column)<BR><BR>Ok, see those 3 columns. Usually, I would just do:<BR>Select * from test where email = blah<BR><BR>HOWEVER, this time I just need the sql statement to have a variable that uses ONE word to describe it as a column, NOT naming it. Pseudo code:<BR><BR>Select * from test where querystring = columnname<BR><BR>So if there are 3 columns, I can just make sure that if ANY column (not just one) matches that qstring, the records show. What is the word to = columnname?<BR><BR>is it colname? Columnname? Or do I HAVE TO mention the actual individual column name? Is there just a standard one word term I can use so it knows to just SEARCH for a column with x criteria?<BR><BR>Thanks. If you are confused, i am sorry, it&#039;s just hard to explain.

  2. #2
    Join Date
    Dec 1969

    Default Relational DBs are a bad choice...

    ...for this kind of thing! You really should look into a DB with full text search capability.<BR><BR>But to answer your question:<BR><BR>SELECT * FROM table WHERE field1 LIKE &#039;%query%&#039; OR field2 LIKE &#039;%query%&#039; OR field3 LIKE &#039;%query%&#039;<BR><BR>Oh, and I showed LIKE here instead of = because 95% of the time when people ask the question you did they *really* mean "if the column *contains* the word in question". If you use = with no %...%, then indeed you will get "if the column *is* the word in question."<BR><BR>No, there is no short cut. <BR><BR>Except maybe not using a relational DB for the wrong purpose.<BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default RE: Simple query question...

    Hello again.<BR><BR>You have to explicitly name the columns in your where clause. There is no wildcards or such.<BR><BR>select * from test<BR> where Name = &#039;value&#039;<BR> or email = &#039;value&#039;<BR> or Address = &#039;value&#039;<BR>

Posting Permissions

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