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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:09:02+00:00 2026-05-25T06:09:02+00:00

I am using a sql query such as WHERE name REGEXP ‘[[:<:]]something[[:>:]]’ . Now

  • 0

I am using a sql query such as WHERE name REGEXP '[[:<:]]something[[:>:]]'.

Now this all works great but my results are not ordered by number of matches found which is what I am looking for. Any ideas on how to go about doing this or if it is even possible?

Thanks

Full Query is

    SELECT `Item`.`id`, `Item`.`name`, `Item`.`short_bio`
    FROM `items` AS `Item`
    WHERE ((`Item`.`name` REGEXP '[[:<:]]hello[[:>:]]') OR
           (`Item`.`name` REGEXP '[[:<:]]world[[:>:]]')

Now this query is generated based on user input, each space breaks the thing into a different part that is searched for. I would like to order the results based on the number of matches of all parts, this way the most relevant results are on the top.

  • 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-25T06:09:02+00:00Added an answer on May 25, 2026 at 6:09 am

    I found an UDF some time ago to do this. I’m really sorry I can’t cite the source though.

    DELIMITER //
    
    CREATE DEFINER=`root`@`localhost` FUNCTION `substrCount`(s VARCHAR(255), ss VARCHAR(255)) RETURNS tinyint(3) unsigned
        READS SQL DATA
    BEGIN
        DECLARE count TINYINT(3) UNSIGNED;
        DECLARE offset TINYINT(3) UNSIGNED;
        DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET s = NULL;
    
        SET count = 0;
        SET offset = 1;
    
        REPEAT
            IF NOT ISNULL(s) AND offset > 0 THEN
                SET offset = LOCATE(ss, s, offset);
                IF offset > 0 THEN
                    SET count = count + 1;
                    SET offset = offset + 1;
                END IF;
            END IF;
        UNTIL ISNULL(s) OR offset = 0 END REPEAT;
    
        RETURN count;
    END
    
    DELIMITER ;
    

    There’s also a nifty solution found here.

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

Sidebar

Related Questions

When using this SQL query: Select * from table_name what happens if the name
I am using SQL Query and below are the tables. Organization OrgID Name RAOGID
I am using SQL Query and below are the tables. Organization OrgID Name RAOGID
I am using SQL Query and below are the tables. Organization OrgID Name RAOID
I'm using this SQL query to create an index: $query = CREATE INDEX id_index2
I am trying to learn SQL query optimization using SQL Server 2005. However, I
My project is re engineering a an HTML data grid constructing using SQL query
How to change column order in a table using SQL query in SQL Server
I'm using a SQL query that is similar to the following form: SELECT col1,
I've got a sql query (using MS-SQL 2005) that generates data with these columns:

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.