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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:56:00+00:00 2026-05-26T10:56:00+00:00

I don’t understand how to combine two tables so that I can generate an

  • 0

I don’t understand how to “combine” two tables so that I can generate an answer to this.

Basically I have a CAP database and I’m only concerned with two tables:

ORDERS (ordno, month, year, cid, aid, pid, qty, dollars)
PRODUCTS (pid, pname, city, quantity, price)

I know that i need to generate a new table like the following to get the answer:

Temp (month, year, pname, price)

The way I tried to do it is:

Temp = Select * from (

(Select month, year from Orders)

join

(Select price, pname from Products)

on

orders.pid = products.pid )

The above query gives me an error that I don’t understand: Every derived table must have its own alias.

The next step i’m pretty sure is:

Answer = select max(price), pname, month from Temp where year = 2011 group by month;

I am very new to SQL. If you guys could help me that would be great. If there is a website that can help me learn SQL better please let me know. Thanks!

EDIT: also if there is more than one product that has max price then you need to list all of them for that month.

EDIT 2: SOLVED THANKS!!

  • 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-26T10:56:01+00:00Added an answer on May 26, 2026 at 10:56 am

    EDIT

    If the price of the product ever changes, you will not get a meaningful result.

    SELECT P.pid, P.price, O.month, P.pname FROM 
    products as P
    JOIN orders AS O ON
        P.pid = O.pid       
    JOIN (
        SELECT
            MAX(P.price) AS price
            , O.month           
        FROM
            orders AS O
            LEFT JOIN products AS P ON
                O.pid = P.pid
        WHERE
            O.year = 2011
        GROUP BY
            O.month
    ) AS MX ON
        MX.month = O.month
        AND O.year = 2011
        AND P.price = MX.price
    

    FYI This is how you give a derived table an alias.

    (Select month, year from Orders) AS myAlias
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know why but I can't find a solution to this. I have 3
don't know better title for this, but here's my code. I have class user
Don't think that I'm mad, I understand how php works! That being said. I
Don't know if anyone can help me with this or if it's even possible.
Don't quite understand why this copy constructor is not invoked when I build with
Don't overthink this - there's a very commonly used term and I ... have
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't think my virtualhost is working correctly. This is what I have inside of
DON'T ASK WHY but... I have a regex that needs to be case insensitive
Don't know if this has been answered before. Have custom routes to users. If

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.