w3resource
SQL exercises

SQL Subquery Exercises: Display the name of each company, price for their most expensive product along with their Name

SQL SUBQUERY: Exercise-33 with Solution

33. Write a SQL query to display the name of each company, price for their most expensive product along with their Name.

Sample table: company_mast

Sample table: item_mast


Sample Solution:

SELECT P.pro_name AS "Product Name", 
       P.pro_price AS "Price", 
       C.com_name AS "Company"
   FROM item_mast P, company_mast C
   WHERE P.pro_com = C.com_id
     AND P.pro_price =
     (
       SELECT MAX(P.pro_price)
         FROM item_mast P
         WHERE P.pro_com = C.com_id
     );

Output :

SQL Subqueries Exercise

Practice Online


Sample Database:

Model Database

Query Visualization:

Duration:

Query visualization of Display the name of each company, price for their most expensive product along with their ID - Duration

Rows:

Query visualization of Display the name of each company, price for their most expensive product along with their ID - Rows

Cost:

Query visualization of Display the name of each company, price for their most expensive product along with their ID - Cost

Contribute your code and comments through Disqus.

Previous: Write a SQL query to display the average price of the products which is more than or equal to 350 along with theri names.
Next: Write a query in SQL to find all the details of employees whose last name is Gabriel or Dosio.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming