sql - select row from multiple tables with least performance impact -


i have 2 tables same columns . eg workinfo 1 table , oldworkinfo table. columns can - id , branch , product , data . (id unique primary key.) when transaction completed deleted workinfo , move oldworkinfo .

i write query optimally search workinfo first , oldworkinfo, have perform join operations in other tables.

ie first search in workinfo table , if record available return , otherwise search in oldworkinfo , return record. following sample query have written using union search in both tables.

with squery  (select * workinfo  union select * oldworkinfo) select * squery squery.id=key;  

kindly suggest possible in single query . cannot use plsql option overall joins , other queries become complicated.

as understand, main idea avoid unnecessary scan on big table historical data. query can avoid it:

select * workinfo id = key union select * oldworkinfo  not exists (     select null     workinfo wi wi.id = key ) , id = key 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -