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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:11:06+00:00 2026-05-14T02:11:06+00:00

Can any one help me how to sort rows by relevance for the following

  • 0

Can any one help me how to sort rows by relevance for the following criterion ?

`tbluser`
- - - - - - -
First Name
Last Name

`tbleduc`
- - - - - - -
School
College
University

On the search form the user has following fields

Name
School
College
University

Where School College and University are Optional..

And Name is split into 2 words (other words in middle are omitted), first word is taken as first anme and last word as last name..

Now I would like to implement search based on relevance.

Thanks for the help 🙂

  • 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-14T02:11:07+00:00Added an answer on May 14, 2026 at 2:11 am

    Okay, I tried this for you on Postgres (I don’t have MySQL here, so maybe it’s a little bit different):

    select matches.id,
          (matches.tfirstname
           + matches.tlastname 
           + matches.tschool
           + matches.tcollege
           + matches.tuniversity) as total
    from (
       select u.id,
              (case when u.firstname like '%a%' then 1 else 0 end) as tfirstname,
              (case when u.lastname like '%b%' then 1 else 0 end) as tlastname,
              sum(e2.nschool) as tschool,
              sum(e2.ncollege) as tcollege,
              sum(e2.nuniversity) as tuniversity
       from tbluser u left outer join (
          select e.usr,
                 (case when e.school like '%c%' then 1 else 0 end) as nschool,
                 (case when e.college like '%d%' then 1 else 0 end) as ncollege,
                 (case when e.university like '%e%' then 1 else 0 end) as nuniversity
          from tbleduc e
       ) e2 on u.id=e2.usr
       group by u.id, u.firstname, u.lastname
    ) as matches
    

    I used these DDL statements to create the tables:

    create table tbluser (
      id int primary key,
      firstname varchar(255),
      lastname varchar(255)
    )
    
    
    create table tbleduc (
      id int primary key,
      usr int references tbluser,
      school varchar(255),
      college varchar(255),
      university varchar(255)
    )
    

    And a little bit of example data:

    insert into tbluser(id, firstname, lastname)
                values (1, 'Jason', 'Bourne');
    insert into tbleduc(id, usr, school, college, university)
                values (1, 1, 'SomeSchool', 'SomeCollege', 'SomeUniversity');
    insert into tbleduc(id, usr, school, college, university)
                values (2, 1, 'MoreSchool', 'MoreCollege', 'MoreUniversity');
    

    The query can be simplified a bit, if the relationship between tbluser and tbleduc is 1:1.

    Don’t forget to replace the %a%, %b, … with your variables (I recommend using a prepared statement).

    I hope this template helps as a basic solution – you can tweak it as much as you like 🙂 You can also remove the outermost select statement, to get the counters of the individual results.

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

Sidebar

Related Questions

Can any one please help with select script? desired outcome TABLENAME, ATTRIBUTE, NULLABLE, DATATYPE,
Hopefully someone can help, I've been playing with ASP.NET MVC 2 for a learning
I'm interested in finding out what's the shortest script one can write to replace
I don't profess to be any master of Excel, so when these things arrive
Need some help with a small problem. I'm not too hot on the maths
I have a list of 55 (or any number but 55 at the moment)
I have few DB tables, witch are build using inheritance from one table witch
I'm looking for some advice/opinions on the best way to approach creating a sort-of-dynamic
OK, so I have a C++ project that compiles to a DLL file. I
Just started learning to use the grid so please excuse me for the possibly

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.