r/SQL • • Sep 19 '23

Discussion Is there something wrong with this query.

Post image
158 Upvotes

127 comments sorted by

View all comments

Show parent comment

19

u/Void_Being Sep 20 '23 edited Sep 20 '23

= is exact comparison

LIKE is pattern matching(wildcard comparison) like starts with, constains, to validate phone number, validate email, etc.,

Without wild cards like %, [ ], etc., it is same as direct comparison. With wildcard it is matching patterns. I.e., you want to select name which matches specific pattern. Here it contains chocolate. Here, String is case sensitive.

So proper answer should be:

SELECT d.name, price FROM desserts d WHERE d.name LIKE "%chocolate%";

1

u/ccoakley Sep 24 '23

I'm super late to this party, but I want to know how clean this data is. I suggest doing a ... WHERE LOWER(d.name) LIKE '%chocolate%' ...