Difference between revisions of "SQL Relational operators"

From Lianjapedia
Jump to: navigation, search
m (1 revision: SQL)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
==Purpose==
 
==Purpose==
 
Relational Operators
 
Relational Operators
 
  
 
==Syntax==
 
==Syntax==
 
<expression1> operator <expression2>
 
<expression1> operator <expression2>
 
  
 
==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==
 
Relational Operators compare two expressions and evaluate to either True or False.
 
Relational Operators compare two expressions and evaluate to either True or False.
  
 
+
{| class="wikitable" width="100%"
 
+
{| class="wikitable"
+
 
!Operator||Description
 
!Operator||Description
 
|-
 
|-
|=||True if <expression1> and <expression2> are equal, otherwise False
+
|valign="top"|=||True if <expression1> and <expression2> are equal, otherwise False
 
|-
 
|-
|<||True if <expression1> is less than <expression2>, otherwise False
+
|valign="top"|<||True if <expression1> is less than <expression2>, otherwise False
 
|-
 
|-
|<=||True if <expression1> is less than or equal to <expression2>, otherwise False
+
|valign="top"|<=||True if <expression1> is less than or equal to <expression2>, otherwise False
 
|-
 
|-
|>||True if <expression1> is greater than the <expression2>, otherwise False
+
|valign="top"|>||True if <expression1> is greater than the <expression2>, otherwise False
 
|-
 
|-
|>=||True if <expression1> is greater than or equal to <expression2>, otherwise False
+
|valign="top"|>=||True if <expression1> is greater than or equal to <expression2>, otherwise False
 
|-
 
|-
|<>||True if <expression1> and <expression2> are not equal, otherwise False
+
|valign="top"|<>||True if <expression1> and <expression2> are not equal, otherwise False
 
|-
 
|-
|!=||True if <expression1> and <expression2> are not equal, otherwise False
+
|valign="top"|!=||True if <expression1> and <expression2> are not equal, otherwise False
 
|-
 
|-
|#||True if <expression1> and <expression2> are not equal, otherwise False
+
|valign="top"|#||True if <expression1> and <expression2> are not equal, otherwise False
 
|-
 
|-
|$||True if <expression1> is a sub string of <expression2>.  Both <expression1> and <expression2>must be character strings.
+
|valign="top"|$||True if <expression1> is a sub string of <expression2>.  Both <expression1> and <expression2>must be character strings.
 
|-
 
|-
|<nowiki>|</nowiki>||True if <expression2> is a sub string of <expression1>.  Both <expression1> and <expression2>must be character strings.
+
|valign="top"|<nowiki>|</nowiki>||True if <expression2> is a sub string of <expression1>.  Both <expression1> and <expression2>must be character strings.
 
|-
 
|-
|==||True if <expression1> and <expression2> match, otherwise False.  Both <expression1> and <expression2>must be character strings.  The <expression2> can contain the wildcards below.
+
|valign="top"|==||True if <expression1> and <expression2> match, otherwise False.  Both <expression1> and <expression2>must be character strings.  The <expression2> can contain the wildcards below.
 
|-
 
|-
 
|}
 
|}
 
  
 
Wildcards for == pattern matching:
 
Wildcards for == pattern matching:
  
 
+
{| class="wikitable" width="100%"
 
+
{| class="wikitable"
+
 
!Operator||Description
 
!Operator||Description
 
|-
 
|-
Line 56: Line 48:
 
|-
 
|-
 
|}
 
|}
 
  
 
==Example==
 
==Example==
Line 92: Line 83:
  
  
==Products==
 
Recital, Recital Server
 
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:SQL|Operators,Relational]]
 
[[Category:SQL|Operators,Relational]]

Latest revision as of 11:37, 30 January 2013

Purpose

Relational Operators

Syntax

<expression1> operator <expression2>

See Also

INSERT, SQL OPERATORS, SELECT, UPDATE

Description

Relational Operators compare two expressions and evaluate to either True or False.

Operator Description
= True if <expression1> and <expression2> are equal, otherwise False
< True if <expression1> is less than <expression2>, otherwise False
<= True if <expression1> is less than or equal to <expression2>, otherwise False
> True if <expression1> is greater than the <expression2>, otherwise False
>= True if <expression1> is greater than or equal to <expression2>, otherwise False
<> True if <expression1> and <expression2> are not equal, otherwise False
!= True if <expression1> and <expression2> are not equal, otherwise False
# True if <expression1> and <expression2> are not equal, otherwise False
$ True if <expression1> is a sub string of <expression2>. Both <expression1> and <expression2>must be character strings.
| True if <expression2> is a sub string of <expression1>. Both <expression1> and <expression2>must be character strings.
== True if <expression1> and <expression2> match, otherwise False. Both <expression1> and <expression2>must be character strings. The <expression2> can contain the wildcards below.

Wildcards for == pattern matching:

Operator Description
_ Any single character
% Zero or more characters

Example

SELECT name, address, balance, cost*1.15;
FROM accounts;
WHERE paid_date = date();
ORDER BY name, paid_date
 
SELECT name, address, balance, cost*1.15;
FROM accounts;
WHERE paid_date <= date();
ORDER BY name, paid_date
 
SELECT name, address, balance, cost*1.15;
FROM accounts;
WHERE paid_date <> date();
ORDER BY name, paid_date
 
SELECT name, address, balance, cost*1.15;
FROM accounts;
WHERE name == "%inc%";
ORDER BY name, paid_date
 
SELECT name, address, balance, cost*1.15;
FROM accounts;
WHERE name | "inc";
ORDER BY name, paid_date
 
SELECT name, address, balance, cost*1.15;
FROM accounts;
WHERE name $ "BigCo inc, BigCo plc";
ORDER BY name, paid_date