How to design conditions for WHERE clauses

The WHERE clause is used to set up a filtering condition on the selected columns to extract only those records that fulfill a specified condition.

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

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

The Tabbed Editor displays the WHERE 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 keys to navigate between criteria operator and operands.

The guide covers how to:

Add a WHERE clause

1. On the WHERE 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 WHERE syntax construction that opens, do the following:

WHERE statement

  • Click enter table name to select the column.
  • Click the upper-level operator to filter records based on multiple conditions:
    • 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 WHERE clause.
  • Click the operator to select the comparison or logical operator for the condition.
  • Click enter a value to set the condition to be provided in the WHERE clause.

A list of supported comparison and operators in the WHERE clause

3. When switching to the Text view, you can preview the SELECT statement with the specified WHERE clause.

Preview the WHERE clause

Work with WHERE conditions and condition groups

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

To create a new group

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

  • Click Add a new group icon
  • Click the upper-level group operator and select Add Group

2. Click enter a value to set the conditions to be provided in the WHERE clause.

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

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

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

Remove conditions and groups

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

To remove a group, do one of the following:

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

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.