SQL checking data content

Asked

Viewed 38 times

3

I’m making a search system for my blog (it already looks for post category and tags). Is there any SQL command (or if the SQL itself already does it) that makes it check all the contents of the data found in the table and return me?

Ex: I tag "test" for my post and look for "test" it will return me the right post (because they are N tags for 1 post). Now, if I put in the post content (or title) "I’m taking a test", it will look for the "test" there middle of the other words?

Is there any way to do that or I’ll have to blow up the search results to search word for word?

1 answer

2


To perform a query for the content just use the joker "%". To better understand let’s take the example:

  1. If you want to search a record (e.g. the word sport) that exists at the beginning of some word within the text:

    "SELECT * FROM posts WHERE content LIKE '%sport'"

  2. If you want to research something that ends with the searched word:

    "SELECT * FROM posts WHERE content LIKE 'sport%'"

  3. And finally, if you want to research something that starts and ends with the searched word

    "SELECT * FROM posts WHERE content LIKE '%sports%'"

For more information see the link http://www.w3schools.com/sql/sql_like.asp

Browser other questions tagged

You are not signed in. Login or sign up in order to post.