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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:02:30+00:00 2026-05-31T06:02:30+00:00

I am trying to find rows in a table that follows a specific pattern.

  • 0

I am trying to find rows in a table that follows a specific pattern.
For example, there is a table with three columns, ID, PRODUCT_ID and ACTION respectively.

ID   PRODUCT_ID   ACTION

1    A001                 ABC
2    A001                 DHI
3    A001                 FGH
4    B111                 FGH
5    A001                 JKL
6    A001                 ZAB

I would like to retrieve the records having 3 actions in order, ABC-FGH-ZAB for same PRODUCT_ID. From above example, I would like to get the rows with IDs, 1, 3, and 6 as an answer and the row with ID 4 should be ignored since it has a different PRODUCT_ID. How do I formulate a query to have a result set like below on MySQL?

ID   PRODUCT_ID   ACTION

1    A001                 ABC
3    A001                 FGH
6    A001                 ZAB

I try not to use a nested query unless I have to for a performance reason . The order of ACTION is important, so FGH-ZAB-ABC should not be retrieved.

Thanks in advance

  • 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-31T06:02:31+00:00Added an answer on May 31, 2026 at 6:02 am
    SELECT
        yt1.ID AS First,
        yt2.ID AS Second,
        yt3.ID AS Third
    FROM
        YourTable yt1 
        JOIN YourTable yt2 
            ON yt2.ID > yt1.ID 
            AND yt2.Action = 'FGH' 
            AND yt2.Product_ID = y1.Product_ID
        JOIN YourTable yt3 
            ON yt3.ID > yt2.ID 
            AND yt3.Action = 'ZAB'
            AND yt3.Product_ID = y1.Product_ID
    WHERE
        yt1.Action = 'ABC'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to compare two tables to find rows in each table that
I'm trying to find duplicate rows based on mixed columns. This is an example
I'm trying to find the rows that are in one table but not another,
Trying to find an example that has css rollover using sprites & sliding door
I'm trying to write a query that updates rows in a table if a
I'm trying to parse the rows in a table that I generate using Javascript
I am trying to fetch all rows within a MySQL table that have a
I'm trying to find text on a webpage that's not marked with a specific
I'm trying to find rows where the first character is not a digit. I
I'm trying to find rows which are within ____meters from the given point. THis

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.