Solved

General SQL Query Question

Posted on 1998-12-09
2
162 Views
Last Modified: 2010-03-19
How does one pass a LIKE query to all the fields in a database?  For example, the following:
     SELECT * from Genetics WHERE Genetics.author LIKE '%smith%'
Returns records with "smith" in the authors field, but what if I wanted to search for "smith" in ALL the fields?
I tried
     SELECT * from Genetics WHERE Genetics.* LIKE '%smith%'
And it didn't work (yes, I'm new to SQL).

Any help would be appreciated.

Thanks,

Dave Stephens

0
Comment
Question by:stepherd
2 Comments
 
LVL 2

Accepted Solution

by:
tschill120198 earned 150 total points
ID: 1092184
I would be surprised if there was a way to do it with just a single line of code...  it could be done using UNION.

Suppose the Genetics table had columns "author", "title", "description".  You could use something like the following:

select * Genetics where author like '%smith%'
union
select * Genetics where title like '%smith%'
union
select * Genetics where description like '%smith%'

If you don't know in advance what the columns are you could build the SQL dynamically.


0
 

Author Comment

by:stepherd
ID: 1092185
Thanks for the input. Yeah, I thought this might be the case.  I am building the SQL dynamically using PERL, so it shouldn't be a problem to approach it as you suggest.
Never hurts to ask! Thanks.

--Dave Stephens

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question