I have two tables
CREATE TABLE Posts
(
Id BIGSERIAL NOT NULL,
Content TEXT NOT NULL
);
CREATE TABLE Ads
(
Id BIGSERIAL NOT NULL,
Content TEXT NOT NULL
);
I need to combine these two tables in a proportion and apply ORDER BY and OFFSET. 1 row from Ads table in each 10 rows from Posts table Is there any way I can accomplish this?.
The final rows should be 10 posts - 1 ad - 10 posts - 1 ad. How can achieve the merging two tables with interleaving the result of different selects
Normal UNION will merge all rows without interleaving
SELECT * FROM (SELECT Id, Content, 'Post' AS Type FROM Posts
UNION
SELECT Id, Content, 'Ads' AS Type FROM Ads) AS sel
LIMIT 10;