-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSession_4_Wildcards_Pattern_Matching.sql
More file actions
69 lines (49 loc) · 1.38 KB
/
Copy pathSession_4_Wildcards_Pattern_Matching.sql
File metadata and controls
69 lines (49 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
CREATE DATABASE Session_4;
USE Session_4;
------ 1. LIKE Operators ------
CREATE TABLE Restaurants (
restaurant_id INT PRIMARY KEY,
restaurant_name VARCHAR(100),
city VARCHAR(50)
);
INSERT INTO Restaurants
VALUES (2, 'Royal Dining', 'Surat'),
(1, 'Sunrise Cafe', 'Ahmedabad');
-- Find all restaurants whose names end with 'Cafe'
SELECT * FROM Restaurants
WHERE restaurant_name LIKE "%Cafe";
------ 2. BETWEEN & AND Operators ------
CREATE TABLE Products (
product_id INT PRIMARY KEY,
product_name VARCHAR(100),
price DECIMAL(10,2)
);
INSERT INTO Products
VALUES (101, 'Wireless Mouse', 799.00),
(102, 'Gaming Keyboard', 1999.00);
SELECT * FROM Products
WHERE price BETWEEN 500 AND 1500;
------ 3. IN Operators ------
CREATE TABLE Users (
user_id INT PRIMARY KEY,
user_name VARCHAR(100),
city VARCHAR(50)
);
INSERT INTO Users
VALUES (1, 'Amit', 'Ahmedabad'),
(2, 'Neha', 'Mumbai'),
(3, 'Kailash','Surat'),
(4,'Divyansh','Vadodara');
SELECT * FROM Users
WHERE city IN ('Ahmedabad','Surat','Vadodara');
----- 4. Select artist with 'ar' in their name ------
CREATE TABLE Songs (
song_id INT PRIMARY KEY,
song_name VARCHAR(100),
artist_name VARCHAR(100)
);
INSERT INTO Songs
VALUES (1, 'Kesariya', 'Arijit Singh'),
(2, 'Shape of You', 'Ed Sheeran');
SELECT * FROM Songs
WHERE artist_name LIKE '%ar%';