Comparison and Logical operators are used for testing data values. Sadly the operators to use are not consistent across languages. This article summarises the most common operators for the key web development languages:
- Javascript
- ASP
- PHP
- SQL
For SQL we checked both mySQL and MS SQL. All operators listed here should work in both.
Comparison
| Operator | Javascript | ASP | PHP | SQL |
|---|---|---|---|---|
| Less than | < | < | < | < |
| Less than or equal to | <= | <= | <= | <= |
| Greater than | > | > | > | > |
| Greater than or equal to | >= | >= | >= | >= |
| Equal to | == | = | == (equal) === (identical) |
= |
| Not equal to | != | <> | != (not equal) <> (not equal) !== (not identical) |
<> |
Testing for “identical” in PHP arrived with PHP 4. Two values are identical if they are the same, and the same type. Eg the values “1″ (a string) and 1 (an integer) are equal but not identical.
Logical
| Operator | Javascript | ASP | PHP | SQL |
|---|---|---|---|---|
| AND | && | AND | && AND |
AND |
| OR | || | OR | || OR |
OR |
| NOT | ! | NOT | ! | NOT |
PHP provides two options for AND and OR with different operator precedences. Refer to the PHP manual: Operator Precedence for details.
useful reference lists
- Javascript
- comparison and logical operators (w3schools)
- ASP
- comparison and logical operators (msdn)
- PHP
- comparison operators (php.net)
- logical operators (php.net)
- MS SQL
- comparison and logical operators (msdn)
- MySQL
- comparison operators (mysql.com)
- logical operators (mysql.com)