Home arrow MySQL arrow Page 6 - Speaking SQL (part 2)

Like, You Know, Man... - MySQL

After learning how to insert and edit data in a database, thesecond part of our SQL tutorial takes an in-depth look at the SELECTquery,and explains how to use joins, sub-queries and built-in functions tofocus in on the data you need.

TABLE OF CONTENTS:
  1. Speaking SQL (part 2)
  2. Christmas Presents
  3. Teacher's Pet
  4. Reading Backwards
  5. Count() Me In
  6. Like, You Know, Man...
  7. Joining Them Together
  8. Nest Egg
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 5
January 18, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

MYSQL ARTICLES

- Oracle Unveils MySQL 5.6
- MySQL Vulnerabilities Threaten Databases
- MySQL Cloud Options Expand with Google Cloud...
- MySQL 5.6 Prepped to Handle Demanding Web Use
- ScaleBase Service Virtualizes MySQL Databases
- Oracle Unveils MySQL Conversion Tools
- Akiban Opens Database Software for MySQL Use...
- Oracle Fixes MySQL Bug
- MySQL Databases Vulnerable to Password Hack
- MySQL: Overview of the ALTER TABLE Statement
- MySQL: How to Use the GRANT Statement
- MySQL: Creating, Listing, and Removing Datab...
- MySQL: Create, Show, and Describe Database T...
- MySQL Data and Table Types
- McAfee Releases Audit Plugin for MySQL Users

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: