---
title: "SQL Sub-query that Returns Single Value: Best Example"
description: "Sub queries are like queries with in the query. You can write subquery such that it will return single value or multiple values. Read more example and explanation."
url: https://srinimf.com/2018/01/21/sub-query-to-return-single-value-example-query/
date: 2018-01-21
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2018/01/pexels-photo-1415378.jpeg?fit=1880%2C1171&ssl=1
categories: ["SQL"]
tags: ["SQL tips and tricks", "SUbquery to return single value"]
type: post
lang: en
---

# SQL Sub-query that Returns Single Value: Best Example

Sub-query returns single or multiple values. If you want to write a [Subquery](https://srinimf.com/2010/04/20/db2-join-vs-sub-query/) to return single value, then [you need to](https://srinimf.com/2018/01/23/four-typical-sub-queries-you-need-to-your-project/) include comparison operators. The list is <,>, =, >=<,<= and <>

Related[DB2 DATE, PACK, UNPACK, and TRIM Functions](https://srinimf.com/2015/07/08/db2-dateunpack-and-trim-functions/)

Related[Two Sample Queries for Inserting Multiple Rows in SQL](https://srinimf.com/2022/07/25/top-sql-queries-to-insert-single-row-and-multi-rows/)

Both numeric and strings you can compare. If you want to retrieve data from the RETAIL_PRICES table, when R_PRICE values equal to the maximum price listed in the S_PRICE column of the SALES_PRICES table, then below is the query.

## Sub-query

![](https://i0.wp.com/images.books24x7.com/bookimages/id_112086/p0300-01.jpg)

 

**Listen Audio:**

Related[DB2: DIGITS and SUBSTR Functions](https://srinimf.com/2011/11/20/db2-sql-built-in-functions/)

 

You do not have to use an aggregate function (such as MAX) to return a single value in a subquery.
 

For example, the subquery’s WHERE clause might include a condition that will return only one value.

The important point to remember is ensure your subquery returns single value.

Otherwise, you will receive an error when using a comparison operator.

Related posts

- [Join Vs Sub-query Top Differences to Read Today](https://srinimf.com/2010/04/20/db2-join-vs-sub-query/)DateApril 20, 2010
- [2 Top SQL Queries to Update Table: Subquery and Join](https://srinimf.com/2023/11/09/how-to-update-a-table-neat-way-using-subquery/)DateNovember 9, 2023
- [DB2 Tutorial For Software Developers (4 of 5)](https://srinimf.com/2015/08/06/mainframe-db2-tutorial-for-software-developers-4-of-5/)DateAugust 6, 2015

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2018%2F01%2F21%2Fsub-query-to-return-single-value-example-query%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2018%2F01%2Fpexels-photo-1415378.jpeg%3Ffit%3D1200%252C747%26ssl%3D1&description=SQL%20Sub-query%20that%20Returns%20Single%20Value%3A%20Best%20Example)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2018/01/21/sub-query-to-return-single-value-example-query/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2018/01/21/sub-query-to-return-single-value-example-query/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2018/01/21/sub-query-to-return-single-value-example-query/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2018/01/21/sub-query-to-return-single-value-example-query/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20SQL%20Sub-query%20that%20Returns%20Single%20Value%3A%20Best%20Example&body=https%3A%2F%2Fsrinimf.com%2F2018%2F01%2F21%2Fsub-query-to-return-single-value-example-query%2F&share=email)
-

### Like this:

Like Loading…
