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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:32:25+00:00 2026-05-23T08:32:25+00:00

SELECT rideid, year, model, rating, SUM(Relevance) as SearchRelevance FROM( SELECT rideid, year, model, rating,

  • 0
SELECT rideid, year, model, rating, SUM(Relevance) as SearchRelevance 
FROM( 
SELECT rideid, year, model, rating, 1 as Relevance FROM cars 
WHERE cat LIKE '%$keyword%' 
UNION ALL 
SELECT rideid, year, model, rating, 1 as Relevance FROM cars 
WHERE cat2 LIKE '%$keyword2%') 
AS t GROUP BY rideid ORDER BY SUM(Relevance) DESC ";

Hi all, I got this awesome query with the help of other members, which works very well in sorting my results based on a relevance system. So that when both of my search criteria are filled those results are ordered first.

The problem is that the results which don’t match both criteria (only match 1 criteria) obviously show up in the results, but in a lower order. I want to actually trash those results, is there a way to refine this query so that the only results that come back are the ones that fill both criteria?

Changing the LIKE to = is not an option because the result fields are textareas so mysql needs to search inside the textareas for the keyword.

Thank you

  • 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-23T08:32:25+00:00Added an answer on May 23, 2026 at 8:32 am

    You could just add HAVING SUM(Relevance) = 2 to the outer SELECT, just after the GROUP BY rideid, since Relevance is a count of how many criteria matched. (If you add more criteria later, you’ll need to replace the 2 with a larger number to match.)

    However, you could also write the whole query in a much simpler way: get rid of the sub-select and UNION ALL, and just do WHERE cat LIKE '%$keyword%' AND cat2 LIKE '%$keyword2%'. The whole point of the sub-select and UNION was to make it possible to get results that match only one or the other.

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

Sidebar

Related Questions

SELECT username, (SUM(rating)/count(*)) as TheAverage, count(*) as TheCount FROM ratings WHERE month ='Aug' AND
SELECT NameMonth,Year,Value from Table WHERE Name LIKE '%JERRY%' AND Year = (SELECT MAX(Year) FROM
SELECT * FROM list WHERE list_item LIKE %_1375_% returns results it should not. For
SELECT domain_usage.url, LEFT(url,locate('?',url)) AS cleanURL FROM domain_usage WHERE MONTH(domain_usage.login_date) = (Now()) AND YEAR(domain_usage.login_date) =
SELECT *, SUM( cardtype.price - cardtype.cost ) AS profit FROM user LEFT OUTER JOIN
select p.Id, sum(inc.Quantity) from Products p join Incomes inc group by p.Id order by
select (t1.a + t2.b) sum from (select (aa + bb) a from table_x where
SELECT gameratingstblx245v.gameid,avg( gameratingstblx245v.rating ) as avgrating, count(gameratingstblx245v.rating) as count,gamedata.name ,gamedata.gameinfo FROM gameratingstblx245v LEFT JOIN
SELECT * FROM Customer WHERE Name 'LIKE [a-f]%' How Can I acheive this in
select pck.id, pck.name, deb.last_time from (select id, name from dp_package where name like %s

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.