5. Basic-Data filtering (Where)

Source: Internet
Author: User
Tags logical operators
combine WHERE clause

operator: a keyword used to join or change a clause in a WHERE clause. Also known as logical operators. ADN operator

Input: SELECT Prod_id,prod_price,prod_name
From Products

WHERE vend_id = 1003 and Prod_price <= 10;

Analysis: The WHERE clause contains two conditions and is joined with the and keyword. In fact, you can add multiple filter conditions, each add one will use a ADN.

and : used in the WHERE clause, which requires that all given conditions be met. or operator

Input: SELECT Prod_id,prod_price,prod_name
From Products

WHERE vend_id = 1003 OR prod_price <= 10;

Analysis: only one condition can be satisfied. Order of calculation

A where can contain any number of and and or operators, and allows both to be combined for complex and advanced filtering.

Input: SELECT Prod_id,prod_price,prod_name
From Products

WHERE vend_id = 1002 OR vend_id = 1003 and Prod_price >= 10;

Analysis: The AND operator is treated preferentially before the OR operator is processed. In fact, vend_id = 1002 OR (vend_id = 1003 and Prod_price >= 10);

Parentheses have higher precedence than and and OR. You should use parentheses as much as possible and do not expect the default calculation order. In operator

The in operator is used to specify a range of conditions in which each condition can be matched. In the following is a comma-delimited list of valid values, all enclosed in parentheses.

Input: SELECT Prod_id,prod_price,prod_name
From Products

WHERE vend_id in (1002.1003)
ORDER by Prod_name;

Analysis: The use of in is similar to or somewhat. But in a more advantageous position.

1. In more intuitive, when the election is more obvious;

2. Better management of the order of options;

3.IN executes faster than or;

The biggest advantage of 4.IN is that you can include other SELECT statements that allow you to create a WHERE clause more dynamically. Not operator

Input: SELECT Prod_id,prod_price,prod_name
From Products

WHERE vend_id not in (1002.1003)

ORDER by Prod_name;

Analysis: Not support for use with In,between and exists.

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.