I have 7 tables that I could UNION on (wwith a limit of 30)
OR
should I do 7 separate queries (with a limit of 30) and trace through them using PHP.
Which why is faster? More optimal? In the second way I would have to trace through part of the 7 queries simulataneously and find the top 30 I need.
What is your needs?
As @chris wrote before, this may help you: Complex SQL (Maybe Outer Joins)
select * from (select ... from ... order ... limit 10 ) union all select * from (select ... from ... order ... limit 10) order by ... limit 10
As I know (checked on DB with 50 million rows) - its fater than not using the devired queries.
Before making decisions you need at least to run both kinds of queries with MySql's EXPLAIN and analyze results. Something like this:
EXPLAIN SELECT f1, f2, f3 FROM t1
UNION ALL
SELECT f1, f2, f3 FROM t2;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With