hi every body ,
i wonder which one is best , Union Query or Temporary Table
actually i have 5 tables from where i have to select data and they have the same structure as well .

Now i am confused that i use union All or union Query to select data from all tables or i loop the insert query to insert data in temporary table and then select From that temporary table.

i am sure you expert can better help me. thanks

As a general rule, it is better to have the database engine do as much work as possible. The engine will be able to make use of internals, hidden optimizations, etc; and you will avoid the overhead of transmitting partial results across the network to and from the db server.

In any specific case, if it matters, you have to actually measure the throughput to decide (the engine's optimizations will be for the common or usually expensive cases, and yours may not fit that spec). And if it doesn't matter, then ... it doesn't matter, so don't work too hard!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.