Sql like operator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Sql like operator

Please kindly help me to solve query with Like operator. In the case of extraction of compounds noun with the like operator, how should I write the code? For instance, I want to select any words with chocolate from the table, chocolate pudding, flourless chocolate cake and easy chocolate covered Oreos, etc...

28th May 2021, 2:51 PM
YokoS
22 Answers
+ 8
select * from desserts where name like '%Chocolate%'; try this it will work.
25th Aug 2021, 11:12 AM
Assefa Demses
+ 6
Use LIKE in the WHERE clause of the SELECT query. Your query would resemble the following pattern: SELECT description FROM recipes WHERE description LIKE '%chocolate%'; The percent % symbol is a wildcard metacharacter that tells LIKE to match any character or characters before and after 'chocolate'.
28th May 2021, 3:34 PM
Brian
Brian - avatar
+ 5
%Chocolate%
29th Sep 2021, 11:13 AM
Kenji
Kenji - avatar
+ 4
Irshad shaikh , read both posts done by Brian.
14th Aug 2021, 12:39 PM
Lothar
Lothar - avatar
+ 3
Esther YU , i assume that you are talking about the sololearn in-lesson code coach in sql tutorial. in this case you need to spell it like this: '... %Chocolate%', since the names of the deserts in the table starts with an uppercase letter...
3rd Aug 2021, 10:24 AM
Lothar
Lothar - avatar
+ 1
Thank you for the advice! I could solve the query😊
28th May 2021, 3:49 PM
YokoS
+ 1
Esther YU '%chocolate' matches all strings that end with 'chocolate'. In this exercise you also need to match strings that have 'chocolate' at the beginning and the middle. So use the wildcard (%) at both ends.
3rd Aug 2021, 6:10 AM
Brian
Brian - avatar
+ 1
It works when i put this select * from desserts where name LIKE '%c%'; Which i think is incorrect? Since we’re told to ONLY get results with chocolate and there are two other items on the table containing the letter ‘c’ which do not contain chocolate… is this one bugged??
22nd Aug 2021, 5:12 PM
Josh Playing Games
+ 1
select name,price from desserts where name LIKE '%Chocolate%'; you have to specify the column name instant of *
25th Nov 2022, 5:59 AM
Kishore
+ 1
select name,price from desserts where name like '%chocolate%'; try this I get Answer
2nd Oct 2023, 5:48 AM
VASHANTHA KUMAR K.S
VASHANTHA KUMAR K.S - avatar
0
in SQL tutorial,can anybody help me to correct this query You are having dinner at a restaurant and decide to order a chocolate dessert. Here is the desserts menu: Write a query to output only chocolate desserts. SELECT * FROM desserts where name LIKE 'Chocolate'; error i am getting is No input
14th Aug 2021, 10:42 AM
Irshad shaikh
Irshad shaikh - avatar
0
select * from desserts where name like '%chocolate%'; I tried this but still showing as error. What is incorrect here?
22nd Aug 2021, 5:00 PM
Josh Playing Games
0
Josh Playing Games Sololearn's DB engine is configured to be case sensitive. Chocolate needs to be capitalized.
22nd Aug 2021, 6:03 PM
Brian
Brian - avatar
0
select * FROM desserts WHERE name LIKE '%Chocolate
5th Aug 2022, 5:33 AM
Kapil Saluja
Kapil Saluja - avatar
0
select name, price from desserts where name LIKE '%Chocolate%';
7th Dec 2022, 6:48 PM
scott nguyen
scott nguyen - avatar
0
SELECT * FROM desserts WHERE name LIKE '%Chocolate%';
15th Dec 2022, 8:03 AM
Kamilia Luthfiyyah
Kamilia Luthfiyyah - avatar
0
Dont forget to write chocolate with upper C SELECT * FROM desserts where name like '%Chocolate%';
8th Feb 2023, 12:09 PM
Mr Nebbak Oussama
0
SELECT name,price FROM desserts WHERE name LIKE 'chocolate%'
12th Aug 2023, 4:06 PM
King
0
Select name, price From desserts where name like '%chocolate%'
1st Dec 2023, 11:45 PM
Arletty Noah
Arletty Noah - avatar
- 1
🤔 are you saying you want to extract noun from a sentence using sql like operator 🙀
28th May 2021, 3:31 PM
Ayush Kumar
Ayush Kumar - avatar