MySQL
  Home arrow MySQL arrow Page 6 - Speaking SQL (part 2)
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Speaking SQL (part 2)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2001-01-18


    Table of Contents:
  • Speaking SQL (part 2)
  • Christmas Presents
  • Teacher's Pet
  • Reading Backwards
  • Count() Me In
  • Like, You Know, Man...
  • Joining Them Together
  • Nest Egg

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Speaking SQL (part 2) - Like, You Know, Man...
    ( Page 6 of 8 )

    SQL also offers the LIKE keyword, which is used to return results from a wildcard search and comes in very handy when you're not sure what you're looking for. There are two types of wildcards allowed in a LIKE construct: the % character, which is used to signify zero or more occurrences of a character, and the _ character, which is used to signify exactly one occurrence of a character.

    Let's suppose I wanted a list of all members whose first names contained the letter "e". My query would look like this:

    mysql> SELECT * FROM members WHERE fname LIKE '%e%'; +-----------+-------+---------+---------+----------------------+ | member_id | fname | lname | tel | email | +-----------+-------+---------+---------+----------------------+ | 2 | Jane | Doe | 8373728 | jane@site.com | | 3 | Steve | Klingon | 7449373 | steve@alien-race.com | +-----------+-------+---------+---------+----------------------+ 2 rows in set (0.16 sec)
    I could use LIKE to generate a list of members whose name begins with the letter "s"

    mysql> SELECT * FROM members WHERE fname LIKE 's%'; +-----------+-------+---------+---------+---------------------------- | member_id | fname | lname | tel | email +-----------+-------+---------+---------+---------------------------- | 3 | Steve | Klingon | 7449373 | steve@alien-race.com | 4 | Santa | Claus | 9999999 | santa@the-north-pole.com | +-----------+-------+---------+---------+---------------------------- 2 rows in set (0.00 sec)
    or search through my "videos" collection for movies containing the word segment "man" in their title.

    mysql> SELECT title, director FROM videos WHERE title LIKE '%man%'; +--------------+----------------+ | title | director | +--------------+----------------+ | Hollow Man | Paul Verhoeven | | Woman On Top | Fina Torres | +--------------+----------------+ 2 rows in set (0.05 sec)


    This article copyright Melonfire 2001. All rights reserved.

     
     
    >>> More MySQL Articles          >>> More By icarus, (c) Melonfire
     

       

    MYSQL ARTICLES

    - MySQL Security Tips
    - Designing a MySQL Database: Tips and Techniq...
    - The Three Most Important MySQL Queries
    - Null and Empty Strings
    - MySQL Server Tuning Tips and Tricks
    - MySQL Query Optimizations and Schema Design
    - MySQL Benchmarking Tools and Utilities
    - MySQL Benchmarking Concepts and Strategies
    - Take Some Load off MySQL with MemCached
    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT