Difference between revisions of "SELECT names"

From SQLZOO
Jump to: navigation, search
Line 15: Line 15:
 
==Pattern Matching Strings==
 
==Pattern Matching Strings==
 
<p>This  tutorial uses the '''LIKE''' operator to check names. We will be using the SELECT command on the table '''world''':</p>
 
<p>This  tutorial uses the '''LIKE''' operator to check names. We will be using the SELECT command on the table '''world''':</p>
Some examples:
 
*Countries that start with B
 
<source lang='sql'>
 
SELECT name FROM world
 
WHERE name LIKE 'B%'
 
</source>
 
*Countries that end with 'stan'
 
<source lang='sql'>
 
SELECT name FROM world
 
WHERE name LIKE '%stan'
 
</source>
 
*Countries that contain the letter z
 
<source lang='sql'>
 
SELECT name FROM world
 
WHERE name LIKE '%z%'
 
</source>
 
  
 
<div class="progress_panel"><div>
 
<div class="progress_panel"><div>

Revision as of 20:51, 20 November 2014

namecontinent
AfghanistanAsia
AlbaniaEurope
AlgeriaAfrica
AndorraEurope
AngolaAfrica
....

Pattern Matching Strings

This tutorial uses the LIKE operator to check names. We will be using the SELECT command on the table world:

Summary

The clause name LIKE 'B%' finds those countries that start with "B".

  • The % is a wild-card it can match any characters

Find the country that start with Y

SELECT name FROM world
  WHERE name LIKE 'F%'
SELECT name FROM world
  WHERE name LIKE 'Y%'