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

  • Home
  • SEARCH
  • 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 9160511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:45:23+00:00 2026-06-17T13:45:23+00:00

I have this query: SELECT * FROM mytable WHERE column1 LIKE ‘%word1%’ AND column1

  • 0

I have this query:

SELECT * FROM mytable
WHERE column1 LIKE '%word1%'
AND column1 LIKE '%word2%'
AND column1 LIKE '%word3%'

I need to modify this query to return records for which column1 contains word1 word2 and word3 and nothing else! no other words, just these words.

Example: searching for samsung galaxy s3 should return any combination of samsung s3 galaxy but NOT samsung galaxy s3 lte

  • 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-17T13:45:25+00:00Added an answer on June 17, 2026 at 1:45 pm

    Assuming that column1 contains space separated words, and you only want to match on whole words, something like:

    SELECT * FROM
      (select ' ' + REPLACE(column1,' ','  ') + ' ' as column1 from mytable) t
    WHERE
       column1 like '% word1 %' AND
       column1 like '% word2 %' AND
       column1 like '% word3 %' AND
       REPLACE(REPLACE(REPLACE(column1,
          ' word1 ',''),
          ' word2 ',''),
          ' word3 ','') = ''
    

    Note that this construction does allow the same word to appear multiple times. It’s not clear from the question whether that should be allowed. (Fiddle)


    It would be a far better design if these words were stored as separate rows in a separate table that relates back to mytable. We could then use more normal SQL to satisfy this query. Your example looks like it’s some kind of tagging example. Having a table storing each tag as a separate row (with an ordinal position also recorded, if required) would turn this into a simple relational division problem.


    A way to count how many times a word appears in a column is the expression:

    (LEN(column2) - LEN(REPLACE(column2,'word',''))/LEN('word')
    

    but this would again revert back to matching subsequences of larger words as well as the word itself, without more work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that looks like this SELECT * from myTable WHERE Date
I have a query like this: SELECT TOP 1 ID, DATA, OTHERINF FROM MYTABLE
I have this query: select BUnit, value from myTable where BUnit in (555,556,557,558) and
i have this sql query select * from table where name like ? but
I'm run this query: SELECT id,like - dislike as result FROM mytable Where the
I have this query: SELECT * From checkfinale where AssociateID = 51 AND `CompletedDate`
I have this query: SELECT * FROM sample INNER JOIN test ON sample.sample_number =
Let's say I have this query: select * from table1 r where r.x =
Hi guys I am having issue I have this query: SELECT * FROM useraccount
I have used this query before: SELECT * FROM stone_list WHERE type IN ('ALEXANDRITE','AMETHYST')

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.