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 544107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:37:11+00:00 2026-05-13T10:37:11+00:00

Sorry, I should have explained better: I have a $string and I want ‘table’

  • 0

Sorry, I should have explained better: I have a $string and I want ‘table’ to be ordered by the number of times each value under ‘word’ column appears in that $string.
for that i need a query like:

'SELECT * FROM table WHERE $string 
LIKE CONCAT("%",LOWER(word),"%")...

to find the words, then I would like to order them by appearance so that:

$string = "lollipop lollipop oh la le la le lollipop";
'SELECT * FROM table'
++++++++++table++++++++++
id - word
1  - la
2  - le
3  - lollipop
4  - shooby
+++++++++++++++++++++++++

(some query to table) would output:

++++++++++table++++++++++
id - word
1  - lollipop (appears 3 times)
2  - le (appears 2 times)
3  - la (appears 2 times)
4  - shooby (appears 0 times)
+++++++++++++++++++++++++

what’s the query to do this? (btw it would be nice if the number of times each word appears in the string would show in the select table too).

  • 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-05-13T10:37:11+00:00Added an answer on May 13, 2026 at 10:37 am

    One trick you can use is to replace the word in the original string. Then compare how many characters were lost. Divided by the length of the word, this gives you the total number of occurrences for that word. For example:

    SELECT 
        w.word
    ,   (length(title) - length(replace(title, w.word, ''))) / length(word)
    FROM (select 'lollipop lollipop oh la le la le lollipop' as title) t
    CROSS JOIN (
        select 'la' as word
        union all select 'le'
        union all select 'lollipop'
        union all select 'shooby'
    ) w
    
    -->
    
    la          2.0000
    le          2.0000
    lollipop    3.0000
    shooby      0.0000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: I am using SqlDataAdapters to fill the data sets. Sorry--I should have been
Sorry for the basic question - I'm a .NET developer and don't have much
Sorry the title isn't more help. I have a database of media-file URLs that
Sorry if the title is poorly descriptive, but I can't do better right now
Sorry for the bad heading but I couldnt explain it better. im trying to
If I have a string that looks like this: This is a string with
I have a table which contains a field of type numeric(28,10) . I would
With little sign of the Sphinx. I have 5 pages. At one should look
Sorry to bother again. I have searched tried my best, looked everywhere and still
Several security experts have said in the past that the login page should be

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.