How to design conditions for HAVING clauses

The HAVING clause is used to specify a filtering condition on groups created by the GROUP BY clause.

dbForge Query Builder for SQL Server allows you to create the HAVING clause in the SELECT and INSERT INTO statements.

To work with HAVING clauses, open the Tabbed Editor by clicking Show Tabbed Editor icon Show Tabbed Editor on the Query toolbar or Query menu.

The Having tab of the Tabbed Editor displays the HAVING clause as a tree with the condition and condition groups. A group consists of several conditions or subgroups, combined with a logical operator.

You can use arrow keys for navigation:

  • UP ARROW, DOWN ARROW, LEFT ARROW, and RIGHT ARROW to navigate between conditions and groups.
  • LEFT ARROW and RIGHT ARROW to navigate between criteria operator and operands.

The guide covers how to:

Add a HAVING clause

1. On the Having tab, use one of the following ways to add a new condition:

  • Click Add a new condition icon Add a new condition.
  • Click the upper-level group operator and select Add Condition.

2. In a new HAVING syntax construction that opens, do the following:

HAVING statement

  • Click the upper-level operator to filter records grouped by:

    • AND displays the records when both conditions are TRUE.
    • OR displays the records when at least one of the conditions is TRUE.
    • NOT (AND/OR) meets the opposite condition set in the HAVING clause.
  • Click enter a value to select the column or specify the value provided in the condition of the HAVING clause.
  • Click the operator to select the comparison or logical operator for the condition.
  • Click enter a value to select the column or specify the value provided in the condition of the HAVING clause.

A list of supported comparison and operators in the HAVING clause

3. Switch to the Text view to preview the SELECT statement with the specified HAVING clause.

Preview the HAVING clause

Work with HAVING conditions and condition groups

You can create, modify, or remove groups and conditions in the HAVING clause.

To create a new group

1. On the Having tab, open the group construction by using one of the following ways:

  • Click the upper-level group operator and select Add Group
  • Press CTRL+PLUS SIGN

2. Click the upper-level operator to select the operator for the group

3. Click enter a value to set the conditions to be provided in the HAVING clause.

4. Click the condition criteria operator and select the criteria operator you want from the list.

5. If the condition operator requires operand values, specify them.

6. Switch to the Text view to check the result.

Remove conditions and groups

To remove a condition, click Remove condition icon Remove Condition or navigate to condition and press the DELETE or MINUS SIGN keys.

To remove a group, use one of the following ways:

  • Click Remove group iconRemove Group next to the group
  • Click its logical operator and select Remove Group on the shortcut menu
  • Navigate to the group and press the DELETE or MINUS SIGN keys

To remove all conditions and groups, click the upper-level operator and select CLear All.

You also can copy, cut, and paste conditions and groups with CTRL+C, CTRL+X, and CTRL+V keys.

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Query Builder for SQL Server.
Request a demo

Request a demo

If you consider employing the Query Builder for your business, request a demo to see it in action.
Ready to start using dbForge Query Builder for SQL Server?