Kartik
Kartik

Reputation: 8703

Select limited rows from multiple tables

So this is fairly common knowledge to select rows from multiple tables and stack the results on top of each other:

SELECT * FROM table1
UNION
SELECT * FROM table2
UNION
...

However, if I want only a limited number of rows from each table, then how should I write it?

SELECT * FROM table1 LIMIT 2
UNION
SELECT * FROM table2 LIMIT 2
UNION
...

Clearly doesn't work.

Note that in my case, I have 51 tables, all with the same exact columns.

Upvotes: 1

Views: 143

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133380

could be work this way

( SELECT * FROM table1 LIMIT 2  )
UNION
( SELECT * FROM table2 LIMIT 2 )
UNION
...

Upvotes: 2

Related Questions