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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:51:28+00:00 2026-06-03T02:51:28+00:00

I have a food database and I’m trying to implement a simple search that

  • 0

I have a food database and I’m trying to implement a simple search that would put first items that are “raw” or “least processed”.

For example, when I’m searching for “carrot”, I really don’t want to have to sort through all the processed food (carrot cake, etc), fast food (Wendy’s carrot big mac, etc). I want the first items to be “carrots, raw”, “carrot, boiled”, “carrot frozen”, “carrot, canned”, etc.

Is there a way to do that in MYSQL so that I sort my items by “presence of keyword” first (let’s say : “raw”, “fresh”, “boiled”, “frozen”…) and then all other occurrences after?

Note :

  • the keyword may or may not be present
  • the keyword may be anywhere
  • I must also find the search keyword alone, in this example “carrot” so that “carrot cake” is still in my results.

Thanks a lot!

Joel

  • 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-06-03T02:51:30+00:00Added an answer on June 3, 2026 at 2:51 am

    This might work for you:

    SELECT * FROM foods
    WHERE foods.title LIKE '%carrot%'
    ORDER BY foods.title LIKE '%raw%' DESC, foods.title
    

    The reason it’s DESC is because that will return 0 or 1, and you want the results that returned 1 to be sorted first.

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

Sidebar

Related Questions

I have a MYSQL full text search, matching against items in my database, which
I have an object that represents a food item to order at a restaurant.
I have a function that shrinks the size of a Food bank (represented by
I have search strings, similar to the one bellow: energy food olympics 2010 Terrorism
I currently have a database structure with two important tables. 1) Food Types (Fruit,
I have a database of items. Each item is categorized with a category ID
I have two tables in my database - Category and Food. Food has idCategory.
Say I have a database with two tables: food, and whatToEat. I query the
I have something like Facebook's Wall build on PHP that uses MySQL database. Structure:
I have recently created an Android application that allows users to add shopping items

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.