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

  • Home
  • SEARCH
  • 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 7860155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:10:47+00:00 2026-06-02T22:10:47+00:00

So I have a table that looks like this: cid | tid | score

  • 0

So I have a table that looks like this:

cid  |  tid  |  score
-----+-------+-------
 6   |  383  |   88
 2   |  234  |   91
 3   |  685  |   77
 5   |  543  |   97
etc...

What I am trying to do is find an ordinal field pattern in the tid column, then search for other instances of that pattern in the same column. For example:

I query to display all tids of a single cid, ordered by descending score:

cid  |  tid  |  score
-----+-------+-------
 6   |  909  |  100
 6   |  119  |   99
 6   |  221  |   98
 6   |  765  |   97
etc...

A pattern is established in the tid column: 909, 119, 221, 765. Now I want to find other possible instances of that pattern, where the cid value is something else. (Note: different cids can have the same tids, so cid 6 can have tid 909, and cid 4 can too.)

I want to check for the pattern in a second query. The pattern values can be spaced out, but they must appear in order:

                           QUERY 2:    
cid  |  tid  |  score           cid    tid     score
---------------------         ---------------------
 6   |  909  |  100             5    | 909 < | 100
 6   |  119  |   99             5    | 831   |  97
 6   |  221  |   98             5    | 793   |  96
 6   |  765  |   97             5    | 435   |  96
                                5    | 404   |  95
                                5    | 119 < |  94
                                5    | 221 < |  94
                                5    | 765 < |  94

After the comparison, I would like MySQL to return something like:

cid |  tid pattern  | instances (in order)
----+---------------+----------------------
 5      909               1 (or 0)
 5      119               1 (or 0)
 5      221               1 (or 0)
 5      765               1 (or 0)

Is there a reasonable way to do this in MySQL? Any help appreciated.

  • 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-02T22:10:48+00:00Added an answer on June 2, 2026 at 10:10 pm

    Gnerally this kind of operation doesn’t work well across rows – Start by pulling it into a single record per cid:

     INSERT INTO summary (c_id, tids)
     SELECT cid, GROUP_CONCAT(tid ORDER BY score DESC)
     FROM yourtable
     GROUP BY cid;
    

    Then you can easily get a list of all combinations where the patterns match or are a superset:

     SELECT a.cid, a.tids, b.cid, b.tids
     FROM summary a, summary b
     WHERE a.cid<>b.cid
     AND a.cid=6
     AND b.tids LIKE CONCAT('%', a.tids, '%');
    

    You might want to have a look at levenstein functions or convolution (hint: if you’re not analysing genomes then have a look at some code which does).

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

Sidebar

Related Questions

I have a table that looks like this: nid vid tid 1 2 3
I have a table that looks like this: <table> <thead> <!-- random table headings
I have a table that looks like this: |StreetName NR| NR | |Teststreet 34|
I have a table that looks like this: id count 1 100 2 50
I have a table that looks like this for about ~30 students: StudentID Course*
I have a table that looks like this: ╔════╦═════════╦═════════╦═══════╗ ║ id ║ deleted ║
I have a table that looks like this: id| country | =================== 1 |
I have a table that looks like this: Name Job Year ImpFile ImpDate ------------------------------------------------
So I have a table that looks like this: ProjectID TaskID Date 000 001
Using sqlite3, I have a table that looks like this: +---------+-----------------+----------+-----------+--------+ | ArtId |

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.