Difference between revisions of "SQL Logical operators"

From Lianjapedia
Jump to: navigation, search
 
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
==Purpose==
 
==Purpose==
 
Logical Operators
 
Logical Operators
 
  
 
==Syntax==
 
==Syntax==
 
<condition1> AND <condition2>
 
<condition1> AND <condition2>
 +
 
NOT <condition>
 
NOT <condition>
 +
 
<condition1> OR <condition2>
 
<condition1> OR <condition2>
 +
 
<condition1> XOR <condition2>
 
<condition1> XOR <condition2>
 
  
 
==See Also==
 
==See Also==
 
[[SQL INSERT|INSERT]], [[SQL OPERATORS]], [[SQL SELECT|SELECT]], [[SQL UPDATE|UPDATE]]
 
[[SQL INSERT|INSERT]], [[SQL OPERATORS]], [[SQL SELECT|SELECT]], [[SQL UPDATE|UPDATE]]
 
  
 
==Description==
 
==Description==
  
 
+
{| class="wikitable" width="100%"
 
+
{| class="wikitable"
+
 
!Operator||Description
 
!Operator||Description
 
|-
 
|-
|AND||True if <condition1> and <condition2> conditions are both true, otherwise False
+
|valign="top"|AND||True if <condition1> and <condition2> conditions are both true, otherwise False
 
|-
 
|-
|NOT||True if the <condition> is false, otherwise False
+
|valign="top"|NOT||True if the <condition> is false, otherwise False
 
|-
 
|-
|OR||True if <condition1> or <condition2> is true or if both conditions are true, otherwise False
+
|valign="top"|OR||True if <condition1> or <condition2> is true or if both conditions are true, otherwise False
 
|-
 
|-
|XOR||True if <condition1> or <condition2> is true but not both, otherwise False
+
|valign="top"|XOR||True if <condition1> or <condition2> is true but not both, otherwise False
 
|-
 
|-
 
|}
 
|}
 
  
 
==Example==
 
==Example==
Line 60: Line 57:
  
  
==Products==
 
Recital, Recital Server
 
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:SQL|Operators,Logical]]
 
[[Category:SQL|Operators,Logical]]

Latest revision as of 13:05, 20 November 2015

Purpose

Logical Operators

Syntax

<condition1> AND <condition2>

NOT <condition>

<condition1> OR <condition2>

<condition1> XOR <condition2>

See Also

INSERT, SQL OPERATORS, SELECT, UPDATE

Description

Operator Description
AND True if <condition1> and <condition2> conditions are both true, otherwise False
NOT True if the <condition> is false, otherwise False
OR True if <condition1> or <condition2> is true or if both conditions are true, otherwise False
XOR True if <condition1> or <condition2> is true but not both, otherwise False

Example

// AND
SELECT name, address, balance, cost*1.15;
FROM accounts;
WHERE paid_date < date() AND ord_value > 10000;
ORDER BY name, paid_date
 
// NOT
SELECT name, address, balance, cost*1.15;
FROM accounts;
WHERE paid_date < date() AND NOT ord_value BETWEEN 0 AND 10000;
ORDER BY name, paid_date
 
// OR
SELECT name, address, balance, cost*1.15;
FROM accounts;
WHERE paid_date < date() OR ord_value > 10000;
ORDER BY name, paid_date
 
// XOR
SELECT name, address, balance, cost*1.15;
FROM accounts;
WHERE paid_date < date() OR ord_value > 10000;
ORDER BY name, paid_date