Difference between revisions of "Like"

From SQLZOO
Jump to: navigation, 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...")
 
Line 19: Line 19:
 
<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}}

Revision as of 11:18, 11 July 2012

How do I use LIKE in a sql SELECT statement.

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 %.

CREATE TABLE bbc (name VARCHAR(10), region VARCHAR(10));
INSERT INTO bbc VALUES ('Poland', 'Europe');
INSERT INTO bbc VALUES ('Zambia', 'Africa');
SELECT name FROM bbc
WHERE name LIKE 'Z*'
SELECT name FROM bbc
WHERE name LIKE 'Z%'
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense