0% found this document useful (0 votes)
46 views

MySQL Practical 5

The document discusses SQL pattern matching and the LIKE operator in MySQL. It provides examples of using wildcards like % and _ with the LIKE operator to match partial strings or single characters. It then provides an exercise to apply these concepts by finding customers based on name patterns from a sample database. The exercise includes queries to find customers by first name starting with "M", suppliers with exactly 10 characters in their name, and customers from cities starting with "C".

Uploaded by

crybert zinyama
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

MySQL Practical 5

The document discusses SQL pattern matching and the LIKE operator in MySQL. It provides examples of using wildcards like % and _ with the LIKE operator to match partial strings or single characters. It then provides an exercise to apply these concepts by finding customers based on name patterns from a sample database. The exercise includes queries to find customers by first name starting with "M", suppliers with exactly 10 characters in their name, and customers from cities starting with "C".

Uploaded by

crybert zinyama
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

M.

Chinyuku Database Systems 2023

MySQL Practical 5- LIKE Operator and


Wild Cards
Pattern Matching
• SQL pattern matching enables you to use “_” to match any single character

• “% “to match an arbitrary number of characters (including zero characters).

• In MySQL, SQL patterns are case-insensitive by default.

• Use the LIKE or NOT LIKE comparison operators.

The LIKE operator and Wild Cards


• The basic operators (=, <, >) do not work well with text data.
• The LIKE operator is used in searches that involve patterns.
• Wildcards are used with the LIKE function to broaden search options.
• A wildcard is a character that can be substituted for zero or more strings.

Wildcard Function Example Comment


% Can be used before and after Like “%mango%” would SELECT * FROM Customer
the text being searched for return: mango, big s
to accept any number of mango, mango groove, WHERE City LIKE 'ha%';
characters before or after mangoes
the text.
_ Any single character Like “b_g” would return: SELECT * FROM Customer
bag, beg, big s
WHERE City LIKE '_arare';
# Any single digit Like ‘1#’ would return:  SELECT * FROM Orders
10, 11, 12, 13,14, WHERE Quantity LIKE ‘1#’;
15,16,17,18,19
Exercise
Use the “exercise 4” database you created in practical 4 to do the exercise.

1. Find all customers whose first names begin with the letter ‘M’

SELECT * FROM customer WHERE FirstName LIKE 'M%';

Page 1|2
M. Chinyuku Database Systems 2023

2. Find all supplier names with exactly ten characters.

SELECT * FROM Supplier WHERE SupplierName LIKE '__________';

3. List all customer last names and addresses who are from the city whose name starts with
character ‘C’

SELECT LastName, Address


FROM Customer
WHERE City LIKE ‘C%’;

Page 2|2

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy