Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

General SQL Query Question

Posted on 1998-12-09
2
Medium Priority
?
167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
tschill120198 earned 600 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

Industry Leaders: 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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

636 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