Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easiest way to implement free text search

Status
Not open for further replies.

Naoise

Programmer
Dec 23, 2004
318
IE
tblA
============
fdA | fdB | fdC | fdD

Is there an easy way of searching all the fields in a particular table to see if any of them contain a particular value? I'm trying to avoid having to build a statement like

SELECT * FROM tblA
WHERE fdA LIKE '%MYSTRING%'
OR fdB LIKE '%MYSTRING%'
OR fdC LIKE '%MYSTRING%'
OR fdD LIKE '%MYSTRING%'

as the table schema may change leaving my query outdated.
 
several database systems offer fulltext searching

however, they usually involve declaring the colulmns over which the fulltext index pertains

hence with a change in the columns, you'd have to change the index, which is the same predicament you anticipate with the OR LIKE scenario

r937.com | rudy.ca
 
And what about something like this ?
SELECT * FROM tblA
WHERE fdA || fdB || fdC || fdD LIKE '%MYSTRING%'

If any searched column may hold NULL value you may consider using COALESCE.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top