TRUE
TRUE is a logical constant in SQL that represents the boolean numerical truth value positive. It is used in logical expressions to check if certain conditions are true or not. It forms part of SQL's Boolean data type category alongside FALSE and UNKNOWN.
Example
SELECT TRUE;
Output
1
Explanation
In MySQL, TRUE is an expression which evaluates to 1.
Example
SELECT TRUE;
Output
TRUE
Explanation
The SQL command is selecting a Boolean constant value, which in this case is TRUE. The PostgreSQL database management system allows for the use of these types of Boolean constants. Upon execution, the command simply returns the Boolean value TRUE.
Example
SELECT (1 < 2) AS ComparisonResult;
Output
| ComparisonResult ||----------------------|| TRUE |
Explanation
The SQL code is comparing 1 and 2. Since 1 is less than 2, the output of the comparison is TRUE. The ‘AS’ keyword is used to assign an alias ‘ComparisonResult’ to the resulting value, making the output easier to understand.
Example
SELECT 1 FROM dual WHERE 2 > 1;
Output
1
Explanation
In this example, the query is returning the value 1
from the dual table where the condition 2 > 1
is true. As 2 > 1
is always true, the output will always be 1
.