mcarlie Posted March 1, 2012 Share Posted March 1, 2012 I'm creating a website with articles that exist within a certain database. When you click on an article there's a small section called "similar articles" which contains articles which contain that same "tags" as the currently viewed article. For example if the article that you're looking at has a tag called "cars" then the "similar articles" section will contain articles that have the specific tag. The problem is that the currently viewed article is also in the "similar articles" section so what I'm looking to do is get all the articles with the same tag with the exception of the currently viewed article. So something like: SELECT * FROM articles WHERE tags = 'cars' BUT NOT WHERE Id = 'the id of the current article' Quote Link to comment Share on other sites More sharing options...
DavidAM Posted March 1, 2012 Share Posted March 1, 2012 SELECT * FROM articles WHERE tags = 'cars' AND Id != 'the id of the current article' Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 2, 2012 Share Posted March 2, 2012 Off-Topic - Might want to do this: Not sure how you store your tags, but if you have one row per tag SELECT * FROM articles WHERE tags in('cars', 'motors', 'trucks') AND Id != 123 group by Id If you have all tags in a text field (Not recommended): SELECT * FROM articles WHERE tags REGEXP 'cars|motors|trucks' AND Id != 123 group by Id Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.