Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

SQL quickie - any column in where clause?

Thread Tools
 
Search this Thread
 
Old 07 September 2002, 12:44 AM
  #1  
AdrianFRST
Scooby Regular
Thread Starter
 
AdrianFRST's Avatar
 
Join Date: Oct 2000
Posts: 368
Likes: 0
Received 0 Likes on 0 Posts
Post

I need to seach all the columns in a table for a string. My code (simplified looks like):

SELECT * FROM products WHERE <columnname> LIKE '%memory%'

Is there a way of setting <columnname> to be any column in the table? Rather than having to do "productname LIKE '%memory%' OR prodcomment LIKE '%memory%' OR prodmfr LIKE..." etc?
Old 07 September 2002, 02:19 AM
  #2  
TopBanana
Scooby Regular
 
TopBanana's Avatar
 
Join Date: Jan 2001
Posts: 9,781
Likes: 0
Received 0 Likes on 0 Posts
Post

You can't do that but you could use:

SELECT * FROM products WHERE column1+column2+column3 LIKE '%memory%'
Old 08 September 2002, 11:32 PM
  #3  
Mark Jackson
Scooby Regular
 
Mark Jackson's Avatar
 
Join Date: Mar 2002
Posts: 340
Likes: 0
Received 0 Likes on 0 Posts
Post

Assuming your using Oracle, doesent matter, pretty much the same whatever you use,

use PL/SQL or VB to output the columns as a text string and do a text search on the string, theres loads of ways to do it if you use a bit of code.

do a Select * from table where col1 LIKE %memory% or col2 like %memory% or col3 etc etc.



Old 09 September 2002, 11:59 AM
  #4  
AdrianFRST
Scooby Regular
Thread Starter
 
AdrianFRST's Avatar
 
Join Date: Oct 2000
Posts: 368
Likes: 0
Received 0 Likes on 0 Posts
Post

Cheers for the help guys.

I'm using MySQL. I've done it in the code now. I was trying to be clever and make it so the search would include any new colums added to the table without having to modify the code.
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
britishtin
General Technical
4
16 September 2015 11:18 PM
stevem2k
Non Scooby Related
8
06 July 2011 11:11 PM
Mkhan
Non Scooby Related
14
09 August 2001 02:07 AM
SDB
Non Scooby Related
2
26 May 2001 11:55 PM
Richard Gledhill
ICE
1
13 November 2000 12:37 AM



Quick Reply: SQL quickie - any column in where clause?



All times are GMT +1. The time now is 12:17 PM.