Difference between revisions of "Like"

From SQLZOO
Jump to: navigation, search
 
(One intermediate revision by one 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>

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%'
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense