SQL checking data content

3

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

Ex: I put a "test" tag 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 the content of the post (or the title) "I'm doing a test", will it search the "test" there in the middle of the other words?

Is there a way to do this or will I have an explode in the search results to search word for word?

    
asked by anonymous 20.11.2015 / 02:17

1 answer

2

To query the content simply use the wildcard "%". To better understand the example:

  • If you want to search for a record (eg the word sport) that exists at the beginning of a word within the text:

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

  • If you want to search for something that ends with the searched word:

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

  • And finally, if you want to search for something that starts and ends with the searched word

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

  • For more information, see link

        
    20.11.2015 / 02:52