SQL Expressions are used to evaluate to a value. SQL Expressions can be combination of one or more values, operators and SQL functions that evaluate to a value. 

Expressions are used to query database for a specific data set. We can assume SQL Expressions as formulas that are used in SQL Queries to fetch and process data.

Syntax

Basic syntax for SQL Expressions is

SELECT * FROM hostel_name where [expressions];

Different kind of SQL Expressions are as follows

SQL Date Expressions

SQL DATE Expressions returns values such as current_timestamp, current date, checks whether given expression is date or not?

Current_timestamp SQL Expression

SELECT CURRENT_TIMESTAMP;
+---------------------+
| CURRENT_TIMESTAMP |
+---------------------+
| 2016-06-04 14:34:09 |
+---------------------+
1 row in set (0.00 sec)

GETDATE SQL Expressions

SELECT GETDATE();
+---------------------+
| GETDATE |
+---------------------+
| 2016-06-04 14:49:11 |
+---------------------+
1 row in set (0.00 sec)

ISDATE SQL Expressions

SELECT ISDATE("2016-06-04 14:49:11");
+---------------------+
| ISDATE |
+---------------------+
| true |
+---------------------+
1 row in set (0.00 sec)

SQL Numeric Expressions

Sometime we requires to process mathematical expressions while making sql queries. At that time we can use Numeric SQL Expressions.

Syntax

SELECT numerical_expressions FROM table_name;

Example

SELECT (9 + 2 + (15*3) )/2 AS ANSWER;
+---------+
| ANSWER |
+---------+
| 28.0000 |
+---------+
1 row in set (0.01 sec)

Let us evaluate a equation while using numeric expressions.

Similarly there are several SQL Functions to process data using numerical expressions like AVG(), SUM(), COUNT(), MAX(), LEN(), MID() etc  

SELECT MAX(sid) from student_list;
+----------+
| MAX(sid) |
+----------+
|       12 |
+----------+
1 row in set (0.01 sec)

SQL Boolean Expressions

SQL Boolean Expressions are used to fetch data on the basis of matching condition.

Syntax

SELECT column1, column2 FROM table_name WHERE boolean_expression;

Example

Let us fetch the student from student_list table where sid = 12. Here expression "sid = 12" denotes the boolean expression as its value will be true when sid = 12 else false.

SELECT * FROM student_list where sid = 12;
+-----+-----------+-------+-----------+
| sid | name | year | hostel_id |
+-----+-----------+-------+-----------+
|  12 | Ram Kumar | Third | 4 |
+-----+-----------+-------+-----------+
1 row in set (0.01 sec)

 




If you want to add more comments to the article or you see any thing incorrect please write a comment below and we will surely get back to you.



Trending Articles


Incorrect table definition there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

Web Server vs Application Server Difference Explained

Infix To Postfix Conversion Using Stack in Javascript

SQL Overview

Binary Search Tree Insert node Implementation in Javascript

Evaluate Postfix Expressions Using Stack In Javascript

Linked List Size or Count in Javascript

MYSQL Dump - How to take mysql dump or export mysql data