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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:59:11+00:00 2026-05-21T02:59:11+00:00

I have the following subset of data: Ticker A | Ticker B | Value

  • 0

I have the following subset of data:

Ticker A | Ticker B | Value 1 | Value 2
AAU        AAV        -0.49     0.98
AAU        AAWW       -0.68    -0.34
AAU        AAXJ       -0.82     0.54
AAU        AB         -0.49    -0.98
AAV        AAWW        0.74    -0.52
AAV        AAXJ        0.69     0.36
AAV        AB          0.27    -1.00
AAWW       AAXJ        0.89     0.61
AAWW       AB          0.62     0.54
AAXJ       AB          0.54    -0.34

Using MySQL, I need to return the top 3 (largest values) from both ‘Value 1’ and ‘Value 2’, based on a ticker. For example, I want to find the 3 largest ‘Value 1’ and ‘Value 2’ where the ticker is ‘AAWW’ (which can exist in either the Ticker A or Ticker B column), but I want to see the other ticker associated with it, per value. Based on the data above and that scenario, my desired recordset would be:

Ticker | Value 1 | Ticker | Value 2
AAV      0.89      AAXJ     0.61
AAXJ     0.72      AB       0.54
AB       0.62      AAU     -0.34 

Ideally, I’d like to do this without a stored procedure. Is that possible?

  • 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-21T02:59:11+00:00Added an answer on May 21, 2026 at 2:59 am

    Try this (assuming you don’t have an ID column, otherwise replace @rownum/rank by ID):

    SELECT T1.SUB_Ticker, T1.VALUE1, T2.SUB_Ticker, T2.VALUE2
      FROM
    (SELECT CASE WHEN TickerA = 'AAWW' THEN TickerA ELSE TickerB END Ticker,
            CASE WHEN TickerA = 'AAWW' THEN TickerB ELSE TickerA END SUB_Ticker,
            VALUE1,
            @rownum:=@rownum+1 ‘rank’
      FROM data_table d, (SELECT @rownum:=0) r
     WHERE TickerA = 'AAWW' OR TickerB = 'AAWW'
     ORDER BY VALUE1 DESC
     LIMIT 3) T1
    JOIN
    (SELECT CASE WHEN TickerA = 'AAWW' THEN TickerA ELSE TickerB END Ticker,
            CASE WHEN TickerA = 'AAWW' THEN TickerB ELSE TickerA END SUB_Ticker,
            VALUE2,
            @rownum:=@rownum+1 ‘rank’
      FROM data_table d, (SELECT @rownum:=0) r
     WHERE TickerA = 'AAWW' OR TickerB = 'AAWW'
     ORDER BY VALUE2 DESC
     LIMIT 3) T2 ON T1.rank = T2.rank
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following R script: X <- read.table(/tmp/run178/data/monitor/portal_free_heap_monitor.log, header=T, sep=;) P1 <- subset(X,
I have requirement of selecting s subset of data from a collection using a
I have a property column which can have a subset of the following values
I have following requirement, I have C#/.Net console application, which refers to 'System.Data.Sqlite.dll' 'System.Data.Sqlite.dll'
I have a large data frame with the following fields (example data). #dput(data) gives...
I have the following code snippet, which loads data from a CSV file into
I have the following problem in R: Lets assume the following data frame: a
I have the following for an HTML font tag: data Color = HexColor Int
I have the following data: Splice.Pair proportion 1 AA-AG 0.010909091 2 AA-GC 0.003636364 3
I am using R software (R commander) to cluster my data. I have a

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.