I’ve got two tables in my MySQL database:
DisplayArticles
Id
CategoryId
ArticleId
IsAuto
Articles
Id
CategoryId
Title
Now what I need to do is to write MySQL query that will fill all positions where IsAuto set to true with newest articles from specified category (with the newest one on top position).
For example if I will have articles:
...
53 2 'Article that is older'
54 2 'Article about something funny'
55 6 'Article about something else'
56 2 'Article about something interesting'
And my display articles like:
1 2 12 false
2 2 42 true
3 2 41 true
4 2 23 false
5 2 25 false
Query invoked with with a parameter CategoryId = 2 should modify DisplayArticles table like this:
1 2 12 false
2 2 56 true
3 2 54 true
4 2 23 false
5 2 25 false
Hope this is clear and understandable.
Please help me to write this query.
Thanks for any response.
Following should do it.
The gist of it goes like this
CategoryIDArticleIDfromArticlesin this subselect excludingArticleID‘s that are already assignedWHEREclause only updating whereIsAutoequalstrue.Update statement