Difference between revisions of "Like"

From SQLZOO
Jump to navigation Jump to search
(Created page with "How do I use LIKE in a sql SELECT statement. <div class='ht'> <div> The LIKE command allows "Wild cards". A % may be used to match and string, _ will match any single characte...")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
How do I use LIKE in a sql SELECT statement.
How do I use LIKE in a sql SELECT statement.
<div class='ht'>
<div class='ht'>
<div class=params>schema:gisq</div>
<div>
<div>
The LIKE command allows "Wild cards".
The LIKE command allows "Wild cards".
Line 9: Line 10:
The country Zambia matches because ambia matches with the %.
The country Zambia matches because ambia matches with the %.
</div>
</div>
<source lang=sql class='tidy'>CREATE TABLE bbc (name VARCHAR(10), region VARCHAR(10));
<source lang=sql class='tidy'></source>
INSERT INTO bbc VALUES ('Poland', 'Europe');
<source lang=sql class='setup'></source>
INSERT INTO bbc VALUES ('Zambia', 'Africa');
</source>
<source lang='sql' class='def e-access'>SELECT name FROM bbc
<source lang='sql' class='def e-access'>SELECT name FROM bbc
WHERE name LIKE 'Z*'</source>
WHERE name LIKE 'Z*'</source>
Line 19: Line 18:
<div class="ecomm e-access" style="display: none">Use * to match any sequence and ? to match a single character.</div>
<div class="ecomm e-access" style="display: none">Use * to match any sequence and ? to match a single character.</div>
</div>
</div>
{{SELECT Ref}}

Latest revision as of 13:08, 12 July 2012

How do I use LIKE in a sql SELECT statement.

schema:gisq

The LIKE command allows "Wild cards". A % may be used to match and string, _ will match any single character.

The example shows countries begining with Z. The country Zambia matches because ambia matches with the %.

SELECT name FROM bbc
WHERE name LIKE 'Z*'
SELECT name FROM bbc
WHERE name LIKE 'Z%'