LIKE Operator SQL

LIKE is an operator. It is a way to use wild cards inside patterns in a WHERE clause to search through a column. The percent sign (%) is the wild card used to represent a string not just a single character. There may be more than one percent sign in a statement. A SELECT statement using LIKE would have the syntax:

SELECT column(s) FROM table WHERE column LIKE pattern

In our monopoly_prop table:

prop_idnamepricegroup
1Baltic Ave60purple
2Mediterranean Ave60purple
3Reading Railroad200rr
4Oriental Ave100light blue
5Vermont Ave100light blue
6Connecticut Ave120light blue

we may wish to find all of the properties that are avenues as opposed to railroads, utilities, places, or Boardwalks. The query would take the following form:

SELECT name FROM monopoly_prop WHERE name LIKE '%Ave'

The result should be:

name
Baltic Ave
Mediterranean Ave
Oriental Ave
Vermont Ave
Connecticut Ave

If a percent sign needs to be included in the constant portion of the query, use a backslant before the percent sign like this:

LIKE'%\%Ave'

< INSERT INTO SQL | LIMIT Phrase SQL >


Send notes in disappearing ink!

Interesting Pages