Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8775095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:43:24+00:00 2026-06-13T18:43:24+00:00

I have an SQL query that joins few tables and I want to filter

  • 0

I have an SQL query that joins few tables and I want to filter records using same LIKE condition for many columns of result set.
For example, I have columns t1.Name, t1.FullName, t1.Comment, t2.Name, t3.Description, etc in my query (t1, t2 and t3 are joined tables names) and I want to check whether t1.Name or t1.FullName or t1.Comment or t2.Name or t3.Description is LIKE ‘%sometext%’.
I’m just interested what SQL will be faster?

WHERE t1.FullName LIKE '%sometext%' OR t1.Comment LIKE '%sometext%' OR
      t2.Name LIKE '%sometext%' OR t3.Description  LIKE '%sometext%'

or

WHERE ISNULL(t1.Name,'') + '|' + ISNULL(t1.FullName,'') + '|' + ISNULL(t1.Comment,'') + '|' + ISNULL(t2.Name,'') + '|' + ISNULL(t3.Description,'') LIKE '%sometext%'

Or may be there is some even faster way?
I’m using MS SQL Server 2008 R2.

UPD: I’ve edited my second query to handle situations when some fields are NULL and when concatenation may contain pattern but fields separately don’t.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:43:25+00:00Added an answer on June 13, 2026 at 6:43 pm

    I would keep it written like this:

    WHERE t1.FullName LIKE '%sometext%' OR t1.Comment LIKE '%sometext%' OR
          t2.Name LIKE '%sometext%' OR t3.Description  LIKE '%sometext%'
    

    Several reasons for not using the latter, where faster doesn’t even come into play:

    1. String summary statistics may be used to service the query, and it may combine different indexes on different columns under exceptional circumstances. This is not possible with the concatenated text
    2. t1.FullName + .... may result in NULL – you have to handle this
    3. t1.FullName + .... may result in Text being found between t1.Comment and t2.Name, e.g.
      • t1.Comment Welcome to the hub
      • t2.Name = Blenheim
      • sometext = ‘hubble’
      • .. t1.Comment + t2.Name … = … hubBlenheim matches hubble
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MS SQL query that joins multiple tables and an example of
I have this SQL Query that pulls data from 3 tables. I am unable
I have an SQL query that returns all companies records ignore the ones with
I have a complex query that joins different tables to get the count. There
I created a SQL View that joins a few tables and when tested in
I have an sql query pulling a few results from different tables, one of
I have a few tables in my database and am using left outer joins
I have a MAssive sql query... its of a few tables i innerjoined... and
I have a SQL query that returns a Datatable: var routesTable = _dbhelper.Select(SELECT [RouteId],[UserId],[SourceName],[CreationTime]
I have a SQL query that I'm trying to debug. It works fine for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.