The action symbol that appears in the SQL Base statement-select statement

Source: Internet
Author: User
Tags logical operators

2. Action symbols that appear in the SELECT statement

2.1 Merging Operators
Select A.ename| | ' ' | | To_char (SAL) from EMP A;

2.2 To eliminate duplicate rows

SELECT DISTINCT deptno from EMP;

2.3 The difference between a space, an empty string, and a null

Select ASCII ('), ASCII (NULL), ASCII (') from dual;

Difference:
Explicitly, an empty string is the same value stored in the database as NULL, but NULL can be assigned to any data type, whereas an empty string can only be assigned to a string type

To filter null values, you need to use the following notation

SELECT * FROM EMP where comm are NOT null;

Typical errors (but no error)

SELECT * FROM emp where comm! = NULL;
SELECT * from emp where comm <> null;
SELECT * FROM emp where comm = null;

2.4 Comparison operations
= >= <= <>! = > < in like are NULL is not null between and not between and

SELECT * from EMP where Sal between and 1500; --Includes 800 and 1500
=
SELECT * from emp where Sal >= and sal<= 1500;

SELECT * from emp where Sal is not between and 1500;
=
SELECT * from emp where Sal < n or sal > 1500;

SELECT * from EMP where empno in (7499,7698,7788);
=
SELECT * from emp where empno=7499 or empno=7698 or empno=7788;

SELECT * from emp where ename like ' t% ';
SELECT * from emp where ename ' t% ';

SELECT * from emp where ename like '%t% ';
SELECT * from emp where ename '%t% ';

SELECT * from emp where sal! = 1000
=
SELECT * from emp where Sal <> 1000

2.5 Logical operators
Boolean operation (Boolean) evaluates to: TRUE, FALSE

Non-OR and

And

True and false = False
True and True = True
Flase and false = False


Or

True or false = True
True or True = True
Flase or false = False


Non -

Not true = False

Not false = True

SELECT * from emp where sal! = job= ' clerk '
SELECT * from emp where sal! = or job= ' clerk '

Attention:

Order of precedence issues:
Not > and > OR If you want to override the default priority order, you have to use parentheses

SELECT * from emp where not (job= ' Saleman ' or job= ' clerk ') and Sal > 1000

SELECT * from emp where not job= ' Saleman ' or job= ' clerk ' and sal > 1000

The action symbol that appears in the SQL Base statement-select statement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.