How to code subqueries


1. Write a SELECT statement that returns the same result set as this SELECT statement, but don’t use a join. Instead, use a subquery in a WHERE clause that uses the IN keyword.

SELECT DISTINCT category_name

FROM categories c JOIN products p

ON c.category_id = p.category_id

ORDER BY category_name

2. Write a SELECT statement that answers this question: Which products have a list price that’s greater than the average list price for all products?

Return the product_name and list_price columns for each product.

Sort the results by the list_price column in descending sequence.

3. Write a SELECT statement that returns the category_name column from the Categories table.

Return one row for each category that has never been assigned to any product in the Products table. To do that, use a subquery introduced with the NOT EXISTS operator.

4. Write a SELECT statement that returns three columns: email_address, order_id, and the order total for each customer. To do this, you can group the result set by the email_address and order_id columns. In addition, you must calculate the order total from the columns in the Order_Items table.

Write a second SELECT statement that uses the first SELECT statement in its FROM clause. The main query should return two columns: the customer’s email address and the largest order for that customer. To do this, you can group the result set by the email_address.

5. Write a SELECT statement that returns the name and discount percent of each product that has a unique discount percent. In other words, don’t include products that have the same discount percent as another product.

Sort the results by the product_name column.

6. Use a correlated subquery to return one row per customer, representing the customer’s oldest order (the one with the earliest date). Each row should include these three columns: email_address, order_id, and order_date.

Order a Unique Copy of this Paper

Essay Creek is an academic writing service provided to you by, a London-based company.

  • Experience
    Helping students successfully for 11 years.
  • Confidentiality & Security
    Be sure your information will be kept confidential due to our secure service.
  • Quality & Reliability
    8.5 out of 10 average quality score according to our customers' feedback. 97.45% of orders delivered on time.
  • Versatility
    478 active writers in 68 disciplines.
  • 100% money back guarantee
    You can always request a refund if you are not satisfied with the result.

Read more about us

Our team of writers is comprised of people with necessary academic writing skills and experience in various fields of study.

  • Skilled writers only
    We carefully choose writers to employ, paying attention to their skills and abilities.
  • Competence
    Your order will be assigned to a competent writer who specializes in your field of study.
  • In-depth knowledge
    Our writers know both peculiarities of academic writing and paper formatting rules.
  • Motivation
    We keep updated on results our writers show, motivating them to constantly improve their performance.

Read more about our writers

  • Testimonials
    Our clients' testimonials prove we're doing everything right.

Check for yourself

  • Sample essays
    The best way to understand how well our writers do their work is to view sample essays written by them.

View samples

  • Our Free Essay Tools
    Even more opportunities to improve your academic papers.

Bibliography Generator
Words to Pages Converter
Words to Minutes Converter
College GPA Calculator
Thesis statement generator