needIT
needIT

Reputation: 13

Look for value LIKE something, but exclude a known item in mySQL

Is there a way I can search a posts tags for related posts but exclude the posts that is being searched from the display results? If so how? And where would I place the code at in the query?

Here is what I got so far.

SELECT *
FROM users_posts
WHERE users_posts.title LIKE '%$search_tag%' OR users_posts.summary LIKE '%$search_tag%' OR users_posts.content LIKE '%$search_tag%'
ORDER BY RAND() 
LIMIT 5

Upvotes: 1

Views: 135

Answers (1)

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171579

Just eliminate the current post by adding something like this to your WHERE clause:

and users_posts.id <> @CurrentPostID

Upvotes: 1

Related Questions