Comparison of the Equals, in, like three in SQL

Source: Internet
Author: User

In SQL, the Equals, in, like three of the comparison SQL in the Equals, in, like three can be used for data matching. But the three were not the same.

The equals sign is used to find all data that matches a single value;

in is used to find all data that matches multiple values;

Like is used to find all the data that matches a pattern.

1. The equals sign knows exactly what to look for.

When you know exactly what you're looking for, and you have a single value, you can use the Equals operator to compare data. string, date, or number can be used in the Equals operator. For example, to find a worker named Wang Jing, you can use the equals sign to match:

SELECT name, sex, ID, salary from Employee WHERE name = ' Wang Jing '

————— ——— —— ————

Results

Name Sex ID Salary

Wang Jing female 3004 3000.00

[1row] Www.dedecms.com

2. In

When you know exactly what you're looking for, and you have multiple values, you can use the IN clause to compare data. Numbers, strings, or dates can also be used in the IN clause. For example, to find workers named "Wang Jing", "Wang Li Gang", "Wang Yapeng", you can use the IN clause to match:

SELECT name, sex, ID, salary from Employee WHERE name in (' Wang Jing ', ' Wang Li Gang ', ' Wang Yapeng ')

————— ——— —— ————

Results Name Sex ID Salary

Wang Jing female 3004 3000.00

Wang Ligang male 5003 3000.00

Wang Yapeng male 4004 6000.00

[3rows] Www.dedecms.com

3. Like clause

You can use the LIKE clause to match when you cannot know exactly what you are looking for, but when you know the pattern in which the data you are looking for conforms. In general, the LIKE clause is used only for string types, and some systems are supported for use in date data, but you cannot use the LIKE clause for numeric type data. For example, to find a worker whose name contains the Chinese character "Yan", you can use the LIKE clause to match:

SELECT name, sex, ID, salary from Employee WHERE name like '% swallow% '

Results

Name Sex ID Salary

Yan Liu Female 2002 3000.00

Zhang Minyan female 4002 4000.00

[2rows]

It is important to note that wildcards only have the meaning of wildcards when used in a LIKE clause. When not used in a LIKE clause, it does not have a special meaning and only represents its own value.

For example, use the character "%" in the equals sign to modify the previous example to:

SELECT name, sex, ID, salary from Employee WHERE name = '% swallow% '

Results Name Sex ID Salary

————— ——— —— ————

[0row]

You cannot find any data because the character "%" when using the equals sign only represents its own inclusion, and the employee table does not have a record with the Name column value "% swallow%".

Comparison of the Equals, in, like three in SQL

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.