Q:

From the following tables write a SQL query to find the most expensive product of each company. Return pro_name, pro_price and com_name

0

From the following tables write a SQL query to find the most expensive product of each company. Return pro_name, pro_price and com_name.

Sample table: company_mast

COM_ID COM_NAME
------ -------------
    11 Samsung
    12 iBall
    13 Epsion
    14 Zebronics
    15 Asus
    16 Frontech
 PRO_ID PRO_NAME                       PRO_PRICE    PRO_COM
------- ------------------------- -------------- ----------
    101 Mother Board                    3200.00         15
    102 Key Board                        450.00         16
    103 ZIP drive                        250.00         14
    104 Speaker                          550.00         16
    105 Monitor                         5000.00         11
    106 DVD drive                        900.00         12
    107 CD drive                         800.00         12
    108 Printer                         2600.00         13
    109 Refill cartridge                 350.00         13
    110 Mouse                            250.00         12

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

SELECT A.pro_name, A.pro_price, F.com_name
   FROM item_mast A INNER JOIN company_mast F
   ON A.pro_com = F.com_id
     AND A.pro_price =
     (
       SELECT MAX(A.pro_price)
         FROM item_mast A
         WHERE A.pro_com = F.com_id
     );

Output of the Query:

pro_name	pro_price	com_name
Monitor		5000.00		Samsung
DVD drive	900.00		iBall
Printer		2600.00		Epsion
ZIP drive	250.00		Zebronics
Mother Board	3200.00		Asus
Speaker		550.00		Frontech

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now