Thursday, 18 September 2014

SQL Expressions

An expression is a combination of one or more values, operators, and SQL functions that evaluate to a
value.
SQL EXPRESSIONs are like formulas and they are written in query language. You can also use them to query the database for specific set of data.
Syntax :-
Consider the basic syntax of the SELECT statement as follows :-

SELECT column1, column2, columnN 
FROM table_name 
WHERE [CONDITION|EXPRESSION];

There are different types of SQL expressions, which are mentioned below :-

SQL - Boolean Expressions:-

SQL Boolean Expressions fetch the data on the basis of matching single value. Following is the syntax :-

SELECT column1, column2, columnN 
FROM table_name 
WHERE SINGLE VALUE MATCHTING EXPRESSION;

Consider the CUSTOMERS table having the following records :-

SQL> SELECT * FROM CUSTOMERS;


7 rows in set (0.00 sec)

Here is simple example showing usage of SQL Boolean Expressions :-

SQL - Numeric Expression :-
This expression is used to perform any mathematical operation in any query. Following is the syntax :-

SELECT numerical_expression as OPERATION_NAME
[FROM table_name
WHERE CONDITION] ;

Here numerical_expression is used for mathematical expression or any formula. Following is a simple examples showing usage of SQL Numeric Expressions :-
There are several built-in functions like avg(), sum(), count(), etc., to perform what is known as aggregate data calculations against a table or a specific table column.

SQL - Date Expressions :-
Date Expressions return current system date and time values :-
Another date expression is as follows :-







No comments:

Post a Comment