Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Like

September 13, 1998

The LIKE operator is another extremely powerful tool to help you define your search. In its most simple form, the LIKE operator functions just like the "=" operator. That is, it matches for equality in the WHERE clause. Thus, if we were to search our EMPLOYEES table, the statement:

    SELECT EMP_NAME, EMP_NUM 
    FROM EMPLOYEES
    WHERE EMP_NAME = 'Lim Sing Yuen';

would be the same as saying:

    SELECT EMP_NAME, EMP_NUM 
    FROM EMPLOYEES
    WHERE EMP_NAME LIKE 'Lim Sing Yuen';

In either case, you would get:

    EMP_NAME		EMP_NUM
    -------------------------------
    Lim Sing Yuen	002
    -------------------------------

However, the real umph of the LIKE operator comes from its ability to incorporate wildcards. Specifically, the LIKE operator can be used with the "%" and the "_" operator. The "%" operator can be used to match any string of any length and the "_" operator is used to match any single character. But this is best seen by example. Consider the following:

    SELECT EMP_NAME, EMP_NUM 
    FROM EMPLOYEES
    WHERE EMP_NAME LIKE 'Lim%';

In this case, you would get the following:

    EMP_NAME		EMP_NUM
    -------------------------------
    Lim Li Chuen	001
    Lim Sing Yuen	002
    -------------------------------

Notice that in both cases, the search string begins with "Lim". The "%" wildcard specifies that so long as the string begins with the string "Lim", it matches.

Consider the "_" operator.

    SELECT EMP_NAME, EMP_NUM 
    FROM EMPLOYEES
    WHERE EMP_NUM LIKE '00_';

In this case, you would get all the records returned that included a "00" followed by any other character:

    EMP_NAME	  	EMP_NUM
    -------------------------------
    Lim Li Chuen	001
    Lim Sing Yuen	002
    Loo Soon Keat	003
    -------------------------------

In
Introduction to Databases for the Web | Table of Contents
Null


Up to => Home / Authoring / DB / Intro




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers