Difference between revisions of "SQL Relational operators"

From Recital Documentation Wiki
Jump to: navigation, search
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=SQL RELATIONAL OPERATORS=
 
 
 
==Class==
 
SQL Applications
 
 
 
 
==Purpose==
 
==Purpose==
 
Relational Operators
 
Relational Operators
Line 49: Line 42:
 
|-
 
|-
 
|}
 
|}
 +
  
 
Wildcards for == pattern matching:
 
Wildcards for == pattern matching:
Line 55: Line 49:
  
 
{| class="wikitable"
 
{| class="wikitable"
 +
!Operator||Description
 +
|-
 
|_||Any single character
 
|_||Any single character
 
|-
 
|-
Line 64: Line 60:
 
==Example==
 
==Example==
 
<code lang="recital">
 
<code lang="recital">
EXEC SQL
+
SELECT name, address, balance, cost*1.15;
SELECT name, address, balance, cost*1.15
+
FROM accounts;
FROM accounts
+
WHERE paid_date = date();
WHERE paid_date = date()
+
ORDER BY name, paid_date
ORDER BY name, paid_date;
+
  
EXEC SQL
+
SELECT name, address, balance, cost*1.15;
SELECT name, address, balance, cost*1.15
+
FROM accounts;
FROM accounts
+
WHERE paid_date <= date();
WHERE paid_date <= date()
+
ORDER BY name, paid_date
ORDER BY name, paid_date;
+
  
EXEC SQL
+
SELECT name, address, balance, cost*1.15;
SELECT name, address, balance, cost*1.15
+
FROM accounts;
FROM accounts
+
WHERE paid_date <> date();
WHERE paid_date <> date()
+
ORDER BY name, paid_date
ORDER BY name, paid_date;
+
  
EXEC SQL
+
SELECT name, address, balance, cost*1.15;
SELECT name, address, balance, cost*1.15
+
FROM accounts;
FROM accounts
+
WHERE name == "%inc%";
WHERE name == "%inc%"
+
ORDER BY name, paid_date
ORDER BY name, paid_date;
+
  
EXEC SQL
+
SELECT name, address, balance, cost*1.15;
SELECT name, address, balance, cost*1.15
+
FROM accounts;
FROM accounts
+
WHERE name | "inc";
WHERE name | "inc"
+
ORDER BY name, paid_date
ORDER BY name, paid_date;
+
  
EXEC SQL
+
SELECT name, address, balance, cost*1.15;
SELECT name, address, balance, cost*1.15
+
FROM accounts;
FROM accounts
+
WHERE name $ "BigCo inc, BigCo plc";
WHERE name $ "BigCo inc, BigCo plc"
+
ORDER BY name, paid_date
ORDER BY name, paid_date;
+
 
</code>
 
</code>
  
  
 
==Products==
 
==Products==
Recital Database Server, Recital Mirage Server, Recital Terminal Developer
+
Recital, Recital Server
 
[[Category:Documentation]]
 
[[Category:Documentation]]
[[Category:SQL]]
+
[[Category:SQL|Operators,Relational]]
[[Category:Reference]]
+

Latest revision as of 15:50, 5 July 2011

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


Products

Recital, Recital Server