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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:04:53+00:00 2026-06-15T21:04:53+00:00

I was doing the exercise for sql query, but get to the point where

  • 0

I was doing the exercise for sql query, but get to the point where i have 3 columns with the same name and some of them contains null, what is the option so i can combine them into one column call price instead of 3.

Short database description "Computer firm":

The database scheme consists of four tables:
Product(maker, model, type)
PC(code, model, speed, ram, hd, cd, price)
Laptop(code, model, speed, ram, hd, screen, price)
Printer(code, model, color, type, price)

The table “Product” includes information about the maker, model number, and type (‘PC’, ‘Laptop’, or ‘Printer’). It is assumed that model numbers in the Product table are unique for all the makers and product types. Each PC uniquely specifying by a code in the table “PC” is characterized by model (foreign key referencing to Product table), speed (of the processor in MHz), total amount of RAM – ram (in Mb), hard disk drive capacity – hd (in Gb), CD ROM speed – cd (for example, ‘4x’), and the price. The table “Laptop” is similar to that one of PCs except for the CD ROM speed, which is replaced by the screen size – screen (in inches). For each printer in the table “Printer” it is told whether the printer is color or not (color attribute is ‘y’ for color printers; otherwise it is ‘n’), printer type (laser, jet, or matrix), and the price

Exercise: 7
Find out the models and prices for all the products (of any type) produced by maker B.

my query:

SELECT distinct Product.model, PC.price, Laptop.price,Printer.price as price 
from   Product 
left   join PC 
on     Product.model=PC.model 
left JOIN Laptop 
ON Product.model=Laptop.model 
left join Printer 
on Product.model= Printer.model 
where Product.maker='B';

output:

Your query:

model   price   price   price
1121    850     NULL    NULL
1750    NULL    1200    NULL

correct query:

model   price
1121    850
1750    1200
  • 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-15T21:04:55+00:00Added an answer on June 15, 2026 at 9:04 pm

    try using COALESCE

    SELECT distinct Product.model, 
           COALESCE(PC.price, Laptop.price,Printer.price) as price 
    from Product left join PC 
                on Product.model = PC.model 
         left JOIN Laptop 
                ON Product.model = Laptop.model 
         left join Printer 
               on Product.model = Printer.model 
    where Product.maker='B'
    

    from the definition,

    COALESCE Returns the first nonnull expression among its arguments.
    

    UPDATE 1

    SELECT  a.model, a.price
    FROM    PC a INNER JOIN Product b
                ON a.model = b.model
    WHERE   b.maker = 'makerB'
    UNION
    SELECT  a.model, a.price
    FROM    Laptop a INNER JOIN Product b
                ON a.model = b.model
    WHERE   b.maker = 'makerB'
    UNION
    SELECT  a.model, a.price
    FROM    Printer a INNER JOIN Product b
                ON a.model = b.model
    WHERE   b.maker = 'makerB'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing some exercise from a book and have some problems with the
I'm doing some exercise to understand Java and Swing API. Why do I have
I'm doing exercise #9 from http://openbookproject.net/thinkcs/python/english2e/ch09.html and have ran into something that doesn't make
After doing my exercise in school, I use Sqlite to store my data. But
im doing an exercise where i have to make a parking lot application. The
I'm doing an exercise over loops and have a doubt. I have an array
I'm doing an exercise to flatten nested lists. The code works in console but
I am new to PL/SQL but have plenty of other SQL experience, including Oracle
I'm doing another C++ exercise. I have to calculate the value of pi from
Just started a tutorial in SQL for beginners. I'm doing some exercises now and

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.