Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I need to check the string with the column if the column contains that string or not.

example:String 'how to make pizza' and the column if has 'pizza' i need to fetch that.. like

SELECT * FROM event WHERE ('%how to make pizza%' LIKE EventName);

any idea plz..

share|improve this question
    
Do you mean SELECT * FROM event WHERE 'how to make pizza' LIKE ('%' || EventName || '%') ; –  ypercube Jan 4 '13 at 9:38
    
yeah.. but that returns null.. (column has pizza) –  user670619 Jan 4 '13 at 9:40
    
Does it have 'how to make pizza'? That's what you said (or I thought you did). –  ypercube Jan 4 '13 at 9:43
    
i need to compare this string in table's column.. –  user670619 Jan 4 '13 at 9:46
    
SELECT * FROM event WHERE 'how to make pizza' LIKE ('%' || EventName || '%') ; this retruns null –  user670619 Jan 4 '13 at 9:46

3 Answers 3

up vote 2 down vote accepted

You have to take into consideration the Full-Text Search Functions

Full-text searching is performed using MATCH() ... AGAINST syntax. MATCH() takes a comma-separated list that names the columns to be searched. AGAINST takes a string to search for, and an optional modifier that indicates what type of search to perform. The search string must be a string value that is constant during query evaluation. This rules out, for example, a table column because that can differ for each row.

The initial setup and configuration is very simple

share|improve this answer
    
thank you, i implemented.. –  user670619 Jan 4 '13 at 13:14
    
hi prob is ResultSet reurns nothing,, is it because of In boolean mode... SELECT * FROM event WHERE MATCH (EventName) AGAINST ('how to make pizza' IN BOOLEAN MODE) –  user670619 Jan 4 '13 at 14:43

You cannot check for a match against a part of your string. In order to accomplish your duty, you should split your original string. This may be done inside the query itself, provide you write some function that split your text, as explained in http://stackoverflow.com/questions/1096679/can-mysql-split-a-column . Once you split the string, you may compare every word with your eventname, using the like or = operator.

share|improve this answer

I'm not sure to understand, but if you just want to test if the value exists in the table, just use "EXISTS" and replace * by the ID column.

Else you can use the full text search function : CONTAINSTABLE Here is the documentation :

http://msdn.microsoft.com/fr-fr/library/ms187787%28v=sql.100%29.aspx

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.