You are on page 1of 9

SEU/IS/18/ICT/005

Practical Recording.

Date: 24th September 2020.


Practical Number: 09.
Title: Pattern Matching and Operators
Aims:
 Getting practice to use LIKE conditions for Pattern Matching.
 Getting practice to apply suitable operators in queries.
Task:
1. Pattern matching.
 _ character.
 % character.
2. Operators ALL, AND, BETWEEN, EXISTS, IN, LIKE, NOT, OR, SOME.
Exercise 01.
1. Create a database named “ABC_Marketers”.
CREATE DATABASE ABC_Marketers;
USE ABC_Marketers;

2. Create the table “customers”as table given below in the database “Marketers”.
CREATE TABLE Customers(
Customer_ID int PRIMARY KEY,
Last_name VARCHAR(20),
First_name VARCHAR(20),
Favourite_Website VARCHAR(70) NULL
);

Page 1 of 9
SEU/IS/18/ICT/005

INSERT INTO Customers


VALUES
(4000,"Jackson","Joe","thechothnet.com"),
(5000,"Smith","Jane","digminecreaft.com"),
(6000,"Ferguson","Samantha","bigactivities.com"),
(7000,"Reynolds","Allen","checkyourmath.com"),
(8000,"Anderson","Paige", NULL),
(9000,"Johnson","Derek","techonthenet.com");

3. Find all the records in the customers table in the customers table where the customer’s
last_name begins with ‘J’.
SELECT *FROM Customers
WHERE Last_name LIKE"J%";

4. Find all last_name values from the customers table where the last_name contains the
letter ‘S’.
SELECT *FROM Customers
WHERE Last_name LIKE"%S%";

Page 2 of 9
SEU/IS/18/ICT/005

5. Find all first_name values from the customers table where the first_name ends with
the letter ‘e’.
SELECT first_name FROM customers
WHERE first_name LIKE "%E";

6. Find all the records from the customers table where the last_name is 7 –cbaracter long
and ends with ‘n’.
SELECT * FROM Customers
WHERE last_name LIKE "_______N";

7. Find all of the records in the customers table where the ‘s’ first_name do not contain
‘e’.
SELECT * FROM Customers
WHERE first_name NOT LIKE "%E%";

Page 3 of 9
SEU/IS/18/ICT/005

Exercise 02.
1. In the database “ABC Marketers” ,create table “suppliers” based on the following
table.
CREATE TABLE Suppliers(
Supplier_id INT PRIMARY KEY,
Supplier_name VARCHAR(90),
City VARCHAR(20),
State VARCHAR(20),
turn_over INT
);

INSERT INTO Suppliers


VALUES
(100,"Microsoft","Redmond","Washington",81506000),
(200,"Google","Moutain view","california",71254687),
(300,"Oracle","Redwwod city","California",41657888),
(400,"Kimberly_clark","Irving","Texas",62569823),
(500,"Tysoon Foods","Springdale","Arkansas",16198752),
(600,"SC Johnson","Racine","Georgia",1346897),
(700,"Dole Food Company","Westlake village","california",21579846),
(800,"Flower Food Company","Thomas ville","Georgia",123654789),
(900,"Electronic arts","Redwood city","California",31278954);

Page 4 of 9
SEU/IS/18/ICT/005

2. Retrieve all the records of the suppliers who are either from Georgia or Texas. (IN)
SELECT * FROM suppliers
WHERE state IN("Georgia","Texas");

3. Retrieve all the records of the suppliers who are not from California (NOT IN).
SELECT * FROM suppliers
WHERE state NOT IN("California");

4. Display the names of the suppliers with their supplier_id who has a turn over between
40000000 AND 70000000.
SELECT supplier_id, supplier_name FROM suppliers
WHERE turn_over BETWEEN 40000000 AND 70000000;

Page 5 of 9
SEU/IS/18/ICT/005

5. Display the names and city of the suppliers whose turnover is NOT BETWEEN
20000000 and 60000000.
SELECT Supplier_name , city FROM suppliers
WHERE turn_over NOT BETWEEN 20000000 AND 60000000;

6. Retrieve the suppliers name with their id, whose name of the city begins with R OR
from the state Arkansas.
SELECT supplier_name, supplier_id FROM suppliers
WHERE city LIKE "R%"OR state="Arkansas";

7. In the above database, create the table products based on the following table.
CREATE TABLE Products(
product_ID INT,
product_name VARCHAR(60),
supplier_id INT,
FOREIGN KEY (supplier_id) REFERENCES suppliers(supplier_ID),
unit_price INT
);

Page 6 of 9
SEU/IS/18/ICT/005

INSERT INTO products


VALUES
(148,"Tulip Folwers",800,1200),
(245,"MMS Office Package",100,8500),
(785,"Hamburger",700,100),
(215,"Glass",200,6502),
(549,"Software",300,7546);

SELECT * FROM products;

Page 7 of 9
SEU/IS/18/ICT/005

8. Retrieve the names and IDs of the supliers whose product having a unit price greater
than 1500. (some or any)
SELECT supplier_name supplier_id
FROM suppliers WHERE supplier_id =SOME
(SELECT supplier_id FROM products WHERE unit_price > 1500);

SELECT Supplier_name supplier_id


FROM suppliers WHERE supplier_id =ANY
(SELECT supplier_id FROM products WHERE unit_price>1500);

9. Display the names, city and IDs of the suppliers who has not supplied any product so
far.(ALL)

SELECT supplier_name, supplier_id, city FROM suppliers


WHERE supplier_id !=ALL
(SELECT supplier_id FROM products);

Page 8 of 9
SEU/IS/18/ICT/005

10. Find the output of the following code snippet_id, FROM products WHERE EXISTS
(SELECT supplier_id FROM suppliers);

SELECT supplier_id FROM products


WHERE EXISTS
(SELECT supplier_id FROM suppliers);

Discussion:
 Studied about how to use LIKE conditions for pattern matching.
 Learn about how to apply suitable operators in queries.

Page 9 of 9

You might also like