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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:29:08+00:00 2026-06-07T09:29:08+00:00

select model from ( select price, model from pc where price = (select max(price)

  • 0
select model from (
    select price, model from pc where price = (select max(price) from pc)
    union
    select price, model from laptop where price = (select max(price) from laptop)
    union
    select price, model from printer where price = (select max(price) from printer)
) t1 where price = (select max(price) from (
    select price, model from pc where price = (select max(price) from pc)
    union
    select price, model from laptop where price = (select max(price) from laptop)
    union
    select price, model from printer where price = (select max(price) from printer)
) t2 )

I’m very new to SQL so my question is very simple, but I would like to sort out one point. Am I right that this query can not be simplified to something like this?

select model from (
    select price, model from pc where price = (select max(price) from pc)
    union
    select price, model from laptop where price = (select max(price) from laptop)
    union
    select price, model from printer where price = (select max(price) from printer)
) t1 where price = (select max(price) from t1)

And if it can not be, is it a bad thing that we run two same subqueries?

  • 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-07T09:29:11+00:00Added an answer on June 7, 2026 at 9:29 am

    I still say to go with one table, which is best practice design. (Not duplicating identical tables unnecessarily.)

    CREATE TABLE unified_table (
      product_type,
      price,
      model
    )
    

    Doing so enables this query…

    SELECT
      *
    FROM
      unified_table
    WHERE
      price = (SELECT MAX(price) FROM unified_table)
    

    But, if you can’t, or won’t, trust the optimiser to deal with the consequences of the UNIONs…

    SELECT
      *
    FROM
    (
      SELECT * FROM pc
      UNION ALL
      SELECT * FROM laptop
      UNION ALL
      SELECT * FROM printer
    ) t1
    WHERE
      price = (SELECT MAX(price) FROM (SELECT price FROM pc
                                       UNION ALL
                                       SELECT price FROM laptop
                                       UNION ALL
                                       SELECT price FROM printer
                                      ) t2
              )
    

    The optimiser will understand how to optimise this so as to remove redundant searches.

    EDIT:

    As a compromise, you can make a unified view, and query that…

    CREATE VIEW unified_table AS
      SELECT 'pc'      AS type, * FROM pc
      UNION ALL
      SELECT 'laptop'  AS type, * FROM laptop
      UNION ALL
      SELECT 'printer' AS type, * FROM printer
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SELECT PRODUCTS.p_id, model, price, CATEGORIES.category FROM PRODUCTS, CATEGORIES WHERE PRODUCTS.subcat_id = CATEGORIES.category_id AND PRODUCTS.model
I have a model where I select the proper data from database as below:
The following produces a working select drop down that pulls from my user model:
Understanding Magento Models by reference of SQL: select * from user_devices where user_id =
SELECT *, SUM( cardtype.price - cardtype.cost ) AS profit FROM user LEFT OUTER JOIN
I'm attempting to gather/select data from a MySQL table to check it against new
I have model with ManyToManyField. Now I need form but don't need select field
Hello I' trying to select from joined column: SELECT A.idAd, A.ads_in_Cat, A.title, A.currency, A.price,
Relations: Product(maker, model, type) Laptop(Model, price, speed, ram, hd, screen) PC(model, price, speed, ram,
Relations: Product( maker, model, type ) PC( model, speed, ram, hd, price) Laptop( model,

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.