I have a table like this:
ID Sentence
1 A fox jumped out of the car, and ran away.
2 An Elephant was seen in the jungle.
3 A fox jumped out of the car, and ran towards jungle.
4 A dog was inside the car, and ran towards jungle.
I need to search for Words like Car, ran, and jungle.These words should be presented in the given sentences.
My output should be the following rows, since only those sentences have all those key words:
ID Sentence
3 A fox jumped out of the car, and ran towards jungle.
4 A dog was inside the car, and ran towards jungle.
I tried doing this in SQL and it gives me the output which I want but I wanted to know, if there is any better way to do this.
Create table #temp1(ID int, Sentence varchar(1000))
insert into #temp1 values
(1, 'A fox jumped out of the car, and ran away.')
,(2, 'An Elephant was seen in the jungle.')
,(3, 'A fox jumped out of the car, and ran towards jungle.')
,(4, 'A dog was inside the car, and ran towards jungle.')
select * from #temp1
where Sentence like '%car%' and Sentence like '%jungle%' and Sentence like '%ran%'
I get the same output which I wanted.
ID Sentence
3 A fox jumped out of the car, and ran towards jungle.
4 A dog was inside the car, and ran towards jungle.