Subqueries in SQL Server clauses
Last modified: October 1, 2024
Subqueries in the SELECT, WHERE, and HAVING clauses
Subqueries in these clauses are highlighted like hyperlinks. You can add subqueries to these clauses by typing them instead of columns. To open such subquery for visual editing, click them holding the CTRL key. Subqueries in the SELECT clause may be renamed by entering name into the Alias column.
Subqueries in the GROUP BY and ORDER BY clauses
Subqueries in these clauses should always return only one value (i.e. one row having one column). To add such subquery, type it into the expression box and press ENTER. You can open them for visual editing only by navigating to them with Document Outline.
Subqueries in the SELECT clause
To add a subquery to the SELECT clause:
- In the query document, go to the Selection tab of the tabbed editor (it is placed under the diagram) and click the field in the Column field. The operand editor opens.
- Click
Create Subquery. The program inserts a subquery template into the condition and automatically moves you to the subquery tab of the query document.
Subqueries in the WHERE and HAVING clauses
To add a subquery to the WHERE and HAVING clauses:
-
In the query document create a condition on the WHERE or HAVING tab of the tabbed editor and click
Create Subquery in the Operand editor.
The program inserts a subquery template into the condition and automatically moves you to the subquery tab of the query document.
-
Drag-and-drop a table to the subquery and add the subquery conditions. The subquery template will be populated with the added parameters.
Download dbForge Studio for SQL Server and try it absolutely free for 30 days!
Want to find out more?
Overview
Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All features
Get acquainted with the rich features and capabilities of the tool in less than 5 minutes.
Request a demo
If you consider employing this tool for your business, request a demo to see it in action.