Answer the question
In order to leave comments, you need to log in
How to form a news/events feed from several tables (php/mysql)?
Good afternoon!
I understand that the question has little to do with the specified technologies, but just in case, I indicated them.
I'm trying to generate a news feed. This feed includes news, articles, videos, reports. Each of these data types is in a separate table. At least because they may have a slightly different set of fields (the main ones are the same), each of them has its own categorization.
The simplest thing is to select everything through union, then sort and select the ones you need:
select * from
(select * from news
union
select * from articles) as materials
order by time desc
limit <deisred_offset>, 10
Answer the question
In order to leave comments, you need to log in
select top 10 * from news1 order by postdate desc
union all
select top 10 * from articles1 order by postdate desc
union all
...
This is the easiest option.
Screw here the conditions for sampling for each article (cut-off date, author, etc.) and you will be happy
To make on each table separately on one request.
I don't think it's worth messing around with union.
First, you can make your request even "heavier".
Secondly, I do not think that you have a very large load there, that you have to pervert with the combination of requests.
Well, the last thing, since it comes to that, then do it according to the principle of "fat client". On js, make a request to get the latest news separately, as an example.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question