How to use the SQL select like parameter

Source: Internet
Author: User

How to use the SQL select like parameter

A similar operation uses a WHERE clause to search a column of a particular pattern.

A similar operator
Similar operators are used to search for specified patterns in a column.

Like the SQL syntax

SELECT column_name (s) from
table_name
WHERE column_name like pattern
 
 

For example like Yun in the "person" table:

Address City
p_id LastName FirstName
1 Hansen Ola TIMOTEIVN 10 Sandnes
2 Svendson Tove BORGVN 23 Sandnes
3 Pettersen Kari STORGT 20 Stavanger

Now, we want to select the people who live in a city and start with "S" shaped from the above table.

We use the following SELECT statement:

SELECT * from Persons
WHERE city like ' s% '
   
   

The "%" symbol can be used to define the pattern before and after the wildcard character (missing letter mode).

The result set looks like this:

Address City
p_id LastName FirstName
1 Hansen Ola TIMOTEIVN 10 Sandnes
2 Svendson Tove BORGVN 23 Sandnes
3 Pettersen Kari STORGT 20 Stavanger

Next, we want to select people living in a city, the last "S" form from "person" seating.

We use the following SELECT statement:

SELECT * from Persons
WHERE city like '%s '
 
       
        Address 
           City 
         
p_id LastName FirstName
1 Hansen Ola TIMOTEIVN 10 Sandnes
2 Svendson Tove BORGVN 23 Sandnes
      
      

Next, we want to choose people who live in a city that contains patterns of "tomato sterility virus" "People" seating.

We use the following SELECT statement:

SELECT * from Persons
WHERE city like '%tav% '
 
         
          Address 
             City 
           
_id LastName FirstName
3 Pettersen Kari STORGT 20 Stavanger
The 
 
         
         
also has the potential to choose people living in a city that does not contain the model "tomato sterility virus" in the "People" table, by using not keywords.

We use the following SELECT statement:

 select * from Persons WHERE city isn't like '%tav% ' 
   
 
           
           
_i D lastname firstname address city
1 Hansen ola timoteivn ten sandnes
2 svendson Tove borgvn sandnes
   
 Note: Reprint please indicate from Www.111cn.net/database/database.html

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.