Click here to Skip to main content
15,910,211 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello ,

How to: Specify Multiple Search Conditions for One Column like query

SQL
SELECT title_id, title
FROM titles
WHERE (title LIKE 'Cook') AND
  (title LIKE 'Recipe')




i am using this through this link but its not working
http://msdn.microsoft.com/en-us/library/vstudio/3wt436fh%28v=vs.100%29.aspx[^]
Posted
Comments
Peter Leow 22-Apr-14 1:30am    
"it is not working" is not informative.
Bh@gyesh 22-Apr-14 1:33am    
Hi,
Use 'OR' instead of 'AND' in query.

1 solution

Of course, it did not work. You are using the LIKE without the % which is used to define wildcards (missing letters) both before and after the pattern.
Say
WHERE title LIKE '%Cook%' 

means matching any title that contains "Cook" with or without any suffix and prefix. By omitting % it means exact matching "Cook" the same as
WHERE title = 'Cook'

Now, your query is asking to search for records whose title is both 'Cook' and 'Recipe', apparently, it can never exist.
Read more:
1. sql_like[^]
2. sql_wildcards[^]
 
Share this answer
 
Comments
King Fisher 22-Apr-14 1:53am    
clear.. ;) my 5+
Peter Leow 22-Apr-14 2:13am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900