Home Combine queries to multiple tables having the same columns in to one query
Reply: 0

Combine queries to multiple tables having the same columns in to one query

user927
1#
user927 Published in April 25, 2018, 12:24 pm

I have 6 tables. All of them can have millions and millions of lines of data. All of the tables have object_id, changer_id, date_created columns.

I need to make a query on all of the tables

SELECT object_id
FROM table#
WHERE changer_id=someId
AND date_created > dateA
AND dateCreated < dateB

or its grails equivalent

table#.createQuery().list{
        projections{property('object_id')}
        eq('changer_id', someId)
        ge('dateCreated' dateA)
        le('dateCreated', dateB)
}

Same query will be made on all of the 6 tables, and then the results are combined and all duplicates are removed.

Im not using between because dateB might not always exist so it would be ommited.

Is there a way to combine this query into single query over 6 tables or any other way to make it faster than 6 separate queryes?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30885 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO