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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:58:52+00:00 2026-05-17T15:58:52+00:00

I have a table in a db that has a structure like this: Date

  • 0

I have a table in a db that has a structure like this:

Date
{
    ID,
    Username,
    Label,
    DateTime
}

I want to be able to perform a basic .Contains search in linq on the Username and Label columns, but there’s a catch. I’d like to order by the number of LIKE matches. Here is what I mean by this:

If I have an instance of Data = {ID=1,Username="Shawn",Label="Whatever",DateTime=1/1/2010}

1) If I search User=”awn” and Label=”What” the result has a match order of 2.

2a) User=”haw” and Label=”cat” has a match order of 1

2b) User=”Doug” and Label=”ever” has a match order of 1

3) User=”Chris” and Label=”Fish” has a match order of 0

I’d like to be able to sort on the match order, where an order of 2 is better than 1, then within each match order I’d like to sort by date.

I’d ideally like to be able to do this in linq, but I’m willing to give straight SQL code a chance.

  • 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-17T15:58:52+00:00Added an answer on May 17, 2026 at 3:58 pm

    Coould you try:

    from row in db.Dates
    let x = row.UserName.Contains(username) ? 1 : 0
           + row.Label.Contains(label) ? 1 : 0
    order by x descending
    select new {row.Id, row.UserName, row.Label,
         Value = x};
    

    If not, the same in TSQL using CASE WHEN … THEN 1 ELSE 0 END

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

Sidebar

Related Questions

So I have a database that has a structure something like this: [user_table] user_id,
I have a table in SQL server that has the normal tree structure of
I have a database structure that has a Person table which contains fields such
I have a table in a MySQL Database which has this structure: CREATE TABLE
I have a table that has redundant data and I'm trying to identify all
I have a table that has an insert trigger on it. If I insert
I have a table that has a processed_timestamp column -- if a record has
I have a table that has a primary key that's an INT... I have
I have a table that has 8 million records, with many fields, including lat/long
I have a table that has about 1/2 million records in it. Each month

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.