codescracker


sql

SQL Expressions



« Previous Tutorial Next Tutorial »


Expression in SQL, is basically the combination of one or more values, operators, functions. Here is the general form of SQL expression:

SELECT col1, col2, colN 
FROM table_name 
WHERE [CONDITION|EXPRESSION];

SQL Boolean Expressions

SQL Boolean Expressions are used to fetch data on the basis of matching the single value. Here is the general form of the SQL Boolean Expression:

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

SQL Boolean Expression Example

Here is an example of SQL boolean expression, let's consider the table CUSTOMERS contains the following records:

SQL expressions

Now, if you query the following SQL statement:

SELECT * FROM CUSTOMERS;

After querying the above SQL statement, will fetch the table named CUSTOMERS present in the database to display all the records present in this table as shown here.

SQL boolean expression

And, if you query the following SQL statements:

SELECT * FROM CUSTOMERS WHERE SALARY = 86000;

Then, the above SQL statement will fetch the table named CUSTOMERS present in the database to display all the records present inside this table, whose salary is 86000 as shown here in the following output

SQL expressions syntax

SQL Numeric Expression

SQL numeric expression is basically used in performing any mathematical operations in query. Here is the general form of the SQL numeric expression:

SELECT numerical_expression as  OPERATION_NAME
[FROM table_name
WHERE CONDITION] ;

Here, the numerical_expression is used for the mathematical expression. Here is a simple example, shows the usage of the SQL Numeric Expressions:

SELECT (15 + 6) AS ADDITION from customers;

After querying the above SQL statement, you will see that you have a new browser window opened. Now you have to click on the submit button, then your output will come out as the summation of the expression (15+6) which will be 21 and you will watch there will be that number of rows (depends on how many rows you have created in your table named customers (10 in this case) ) displaying the same result i.e., 21.

It will display the following result:

SQL expression example

If you query the following SQL statement:

SELECT COUNT(*) AS "RECORDS" FROM CUSTOMERS;

It will display the following result

SQL Numeric Function

SQL Date Expressions

SQL Date Expressions returns the current system date and time values. Here is the general form of the SQL Date Expression:

SELECT CURRENT_TIMESTAMP from table_name;

Now, let's concentrate on the following example to understand the SQL Date Expression:

SELECT CURRENT_TIMESTAMP from customers;

Here is the output of the above SQL statement:

SQL date expression

Here is another date expression in SQL:

SELECT GETDATE() from customers;

It will display the same as above:

SQL date expression example

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test