SQL Step-by-Step (14) combination condition and Boolean operator

Source: Internet
Author: User

Combining conditions and Boolean operators

The following SQL statement contains the combination condition:

SELECT Column1, SUM (Column2)

From "List-of-tables"

WHERE "Condition1" and "Condition2";

The AND operator can concatenate two or more conditions in the WHERE clause. Both sides of the and condition must be true (true), that is, when two conditions are both satisfied, the rows will be displayed.

Of course, you can also use the OR operator, which can also connect two or more conditions in the WHERE clause. However, the line is displayed only if the condition is satisfied if either side of the OR operator is true. So when you use the OR operator, you can have only one side of the OR operator on either side is true or both sides are true.

Here's an example:

SELECT EmployeeID, FirstName, LastName, title, salary

From Employee_info

WHERE salary >= 50000.00 and title = ' Programmer ';

This SQL statement selects the columns EmployeeID, FirstName, LastName, title, and salary from the Employee_info table salary greater than or equal to 50000.00 and title equals ' Programmer '. The conditions on both sides of the and operator must be true at this point, and the rows will retrieve the results most. If one of the conditions is false, then nothing is displayed.

You can enclose the conditions in parentheses, although they may not necessarily be necessary, but it is a matter of programming custom to enclose them in a clearer context. Like what:

SELECT EmployeeID, FirstName, LastName, title, salary

From Employee_info

WHERE (Salary >= 50000.00) and (title = ' Programmer ');

Here's another example:

SELECT FirstName, LastName, title, salary

From Employee_info

WHERE (title = ' Sales ') or (title = ' Programmer ');

This statement selects the column FirstName, LastName, title, and salary of title equal to ' Sales ' or equal to ' programmer ' from the Employee_info table.







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.