theorize99
theorize99

Reputation: 67

SQL LIKE operator and wildcard characters

Just started learning SQL, so apologies if I'm missing something simple. I know how to use wildcard characters in conjunction with a LIKE operator, but I'm looking for some slightly different functionality. I'll use an example...

SELECT productID 
FROM productList 
WHERE productName LIKE '%towel%'

would select productID numbers for products such as, say, "Bath Towel" and "Kitchen Towel"

What I need to do is take a string like "Kitchen Towel w/ Red-Brown Stripes" and use this to find the productName "Kitchen Towel." The way I imagine doing this is something like...

SELECT productID 
FROM productList 
WHERE productName% LIKE 'Kitchen Towel w/ Red-Brown Stripes'

Obviously this query does not work, but I need some way of achieving the same goal. Only idea I had was to manipulate the order string prior to the query, cutting it down to "Kitchen Towel", but this isn't repeatable because there is no consistent pattern between orders. Looking for ideas. Thanks to everyone for your time :)

Upvotes: 2

Views: 1219

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271171

I think you want:

where 'Kitchen Towel w/ Red-Brown Stripes' like productname || '%'

Upvotes: 4

Related Questions