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

The Archive Base Latest Questions

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

I am probably trying to accomplish too much in a single query, but have

  • 0

I am probably trying to accomplish too much in a single query, but have I an sqlite database with badly formatted recipes. This returns a sorted list of recipes with relevance added:

SELECT *, sum(relevance) FROM (
  SELECT *,1 AS relevance FROM recipes WHERE ingredients LIKE '%milk%' UNION ALL
  SELECT *,1 AS relevance FROM recipes WHERE ingredients LIKE '%flour%' UNION ALL
  SELECT *,1 AS relevance FROM recipes WHERE ingredients LIKE '%sugar%'
) results GROUP BY recipeID ORDER BY sum(relevance) DESC;

But I’m now stuck with a special case where I need to write the relevance value to a field on the same row as the recipe. I figured something along these lines:

UPDATE recipes SET relevance=(SELECT sum(relevance) ...)

But I have not been able to get this working yet. I will keep trying, but meanwhile please let me know how you would approach this?

Edit: Evaluating Peter’s solution, I ran into some serious performance issues, due to the amount of data the operations had to be performed on. I wrote a little Rebol script that does the loops and and the finding and does commits in 1000-row batches. It completed in a couple of minutes.

  • 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-14T14:50:11+00:00Added an answer on May 14, 2026 at 2:50 pm

    You really should get your model fixed (see below).

    If you can’t, the following query should work (I tried it and it worked as I expected).

    Update recipes
    Set relevance =
    (
      Select   Case When ingredients Like '%milk%' Then 1 Else 0 End
             + Case When ingredients Like '%flour%' Then 1 Else 0 End
             + ...
      From recipes r2
      Where r2.recipe_id = recipes.recipe_id
    )
    

    It uses Case to sum up all matched ingredients.


    Suggested model:

    • Table recipes

    • Table ingredients

    • Table recipe_ingredients

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

Sidebar

Related Questions

I could probably write this myself, but the specific way I'm trying to accomplish
This has probably been answer already but I am trying to return the primary
This is probably a silly question, but I am trying to stuff an anonymous
Okay this is probably a rookie question, but I have never done GUI programming
I have been trying to figure this one out but I am having a
I'm trying to do something which is probably very simple, I have a directory
I'm probably over-thinking this/wasting time trying to avoid a bit of conditional code -
I'm probably missing something obvious here but here's what I'm trying to do. From
I'm trying to do something fairly simple, but for the reason of me probably
I'm trying to pick up Lua programming but I'm stuck on something that's probably

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.