An expression is a combination of one or more values, operators and SQL functions that evaluate to a value. These SQL EXPRESSIONs are like formulae and they are written in query language. You can also use them to query the database for a specific set of data.
Consider the basic syntax of the SELECT statement as follows −
There are different types of SQL expressions, which are mentioned below −
Let us now discuss each of these in detail.
SQL Boolean Expressions fetch the data based on matching a single value. Following is the syntax −
Consider the EMPLOYEES table having the following records −
ID | NAME | AGE | ADDRESS | SALARY |
---|---|---|---|---|
1 | Ravi | 30 | Delhi | 18000 |
2 | Pawan | 26 | Pune | 20000 |
3 | Jignesh | 28 | Surat | 22000 |
4 | Vikram | 25 | Mumbai | 25000 |
5 | Shilpa | 24 | Kolkata | 12000 |
6 | Hardik | 28 | Chennai | 20000 |
The following table is a simple example showing the usage of various SQL Boolean Expressions −
ID | NAME | AGE | ADDRESS | SALARY |
---|---|---|---|---|
6 | Hardik | 28 | Chennai | 20000 |
These expressions are used to perform any mathematical operation in any query. Following is the syntax −
Here, the numerical_expression is used for a mathematical expression or any formula. Following is a simple example showing the usage of SQL Numeric Expressions −
ADDITION |
---|
21 |
There are several built-in functions like avg(), sum(), count(), etc., to perform what is known as the aggregate data calculations against a table or a specific table column.
RECORDS |
---|
6 |
Date Expressions return current system date and time values −
Current_Timestamp |
---|
2017-7-12 12:21:25 |
Another date expression is as shown below −
GETDATE |
---|
2017-7-12 12:25:29.122 |