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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:34:07+00:00 2026-06-04T00:34:07+00:00

In the below code I have two tables. I join these, perform a GROUP

  • 0

In the below code I have two tables. I join these, perform a GROUP BY on “Spot” and then a MIN() on a value calculated via the join.

The problem is that I also wish to obtain the value of Column2 for my resultant rows. At the moment I cannot select this immediately because Column2 is not part of the GROUP BY and it is not part of an aggregate function.

Also, I cannot perform a 3rd JOIN on the data to get this column, because I will just end up going around in circles, as my join condition would be on DerivedValue and in order to get this I will need to produce another GROUP BY….. and I will go around in circles.

If it helps to understand- temp4 is just a table containing 1s and 0s, performing a mask (hence the MIN() is done on the multiplication of these two)…..

EDIT: Please note, the reason why I am joining the same table is because I am effectively subtracting two values from a matrix and it was the easiest way to get the correct values all in one row to subtract.

SELECT temp3.Column1, min(temp3.DerivedValue * Probability) FROM
    (SELECT temp1.Spot AS Spot, temp1.Vol AS Vol, temp1.Value- temp2.Value AS DerivedValue FROM
        (SELECT Spot, Vol, Value FROM My_Table_1) temp1
    INNER JOIN
        (SELECT Spot, Vol, Value FROM My_Table_1) temp2
    ON temp1.Spot = temp2.Spot) temp3
JOIN
    (SELECT Spot, Vol, Probability FROM My_Table_2) temp4
ON temp3.Spot = temp4.Spot AND temp3.Vol = temp4.Vol
GROUP BY temp3.Spot
  • 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-04T00:34:09+00:00Added an answer on June 4, 2026 at 12:34 am

    You cant select a column not present in either in the GROUP BY clause or aggregation. The reason is that there is no way to compress values from multiple rows into one data cell. For example if you group 20 rows into one, how to decide which value to select into the result in this row? You should instruct the query to select the right value, either with grouping on it, or aggregating somehow.

    Otherwise it can’t be done. Maybe consider to rephrase your question to get some workaround for your exact problem.

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

Sidebar

Related Questions

I have code below: <select id=testSelect> <option value=1>One</option> <option value=2>Two</option> </select> <asp:Button ID=btnTest runat=server
I have the following code that will join two different tables together and provide
I have this code below. As you can see I am passing two variables
I have a chart (code to replicate will be below) that has two lines
I have two tables like the below one in my DB. In the first
Say, I have two tables Person and Car and I link these two. The
I have two tables as below: Student: oneID (primary key), col1, col2, col3, subId,
I have two Data Tables and these are completely dynamic. These would be generated
I have two tables like below, mysql> select * from Books ; +----+------+------------+----------+----------+ |
Below I have two tables users and users_profiles Both are innoDB and collation: utf8_general_ci

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.