Answer the question
In order to leave comments, you need to log in
How to join two tables correctly?
There are two tables containing news for different sports:
soccer_news and hockey_news They
are not connected in any way.
You need to connect these two tables and sort by date, then display them through pagination.
Thought to do something like this:
$soccer = App\SoccerNews::get();
$hockey = App\HockeyNews::get();
$collection = new Collection;
$all = $collection->merge($soccer)->merge($hockey);
Answer the question
In order to leave comments, you need to log in
It is better if you have all types of news in one table, and differ by section_id (respectively, 0 - no topic, 1 - football, 2 - hockey, etc.)
Then the request for a portioned selection is elementary.
select a.*
from (select n.*,
rank() over (partition by n.section_id order by n.publication_date desc) rnk -- нумеруем порядок новости в пределах каждой секции по порядку даты публикации
from news n) a
where a.rnk < 10 -- сколько новостей выводить на каждую секцию
order by a.section_id, a.publication_date desc
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question