SQL WHERE: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(12 intermediate revisions by the same user not shown)
Line 5: Line 5:


=Overview=
=Overview=
The <code>WHERE</code> clause is the mechanism for filtering out unwanted data from the [[SQL#Result_Set|result set]]. The <code>WHERE</code> clause can be used with <code>[[SQL_SELECT#WHERE|SELECT]]</code>, <code>[[SQL_UPDATE#Overview|UPDATE]]</code> and <code>[[SQL_DELETE#Overview|DELETE]]</code>, but not with <code>[[SQL_INSERT#Overview|INSERT]]</code>. The <code>WHERE</code> clause may contain an arbitrary number of filter conditions separated by <code>AND</code>, <code>OR</code> and <code>NOT</code> operators, and optionally grouped together with parentheses.
<font size=-1.5>
  <font color=green><b>FROM</b></font> <filter_condition> <font color=green><b>AND</b></font>|<font color=green><b>OR</b></font> <filter_condition> ...
</font>


Filters, conditions, condition evaluation.
<syntaxhighlight lang='sql'>
SELECT * FROM person WHERE person.name = 'Alice' AND (person.eye_color = 'blue' OR person.eye_color = 'black');
</syntaxhighlight>


The <code>WHERE</code> clause can be used with <code>[[SQL_SELECT#WHERE|SELECT]]</code>, <code>[[SQL_UPDATE#Overview|UPDATE]]</code> and <code>[[SQL_DELETE#Overview|DELETE]]</code>, but not with <code>[[SQL_INSERT#Overview|INSERT]]</code>.
=Filter Conditions=
==<tt>NULL</tt> in Conditions==
Also see: {{Internal|SQL#SQL_NULL|<tt>NULL</tt>}}

Revision as of 22:06, 23 May 2024

Internal

Overview

The WHERE clause is the mechanism for filtering out unwanted data from the result set. The WHERE clause can be used with SELECT, UPDATE and DELETE, but not with INSERT. The WHERE clause may contain an arbitrary number of filter conditions separated by AND, OR and NOT operators, and optionally grouped together with parentheses.

  FROM <filter_condition> AND|OR <filter_condition> ...

SELECT * FROM person WHERE person.name = 'Alice' AND (person.eye_color = 'blue' OR person.eye_color = 'black');

Filter Conditions

NULL in Conditions

Also see:

NULL