Back to list
Views:   4.5K
Replies:  2
SQL query question: Calculate AVG, MAX from multiple tables/databases
I am new to writing more involved sql queries and need a bit of help.

I need to write to capture the following:

data from 2 columns in one table in Database 1, then I need to capture 3 columns from one table in Database 2
I think I have an example (keep in mind just an example.) which is working , however I need to AVG one column and MAX another.
I having an issue tying all this together.

Any help would be great, the real assistance would be how to aggregate the data I need and add it to my query.

Any help is appreciated.

David Arena, May 31, 2017
Reply 1
Pls. avg A UNION B ?
Active Ice, May 28, 2018
Reply 2
If you are trying to get data from two databases then this best being done with a UNION. A UNION  combines two separate queries into one. 

A little bit more background about the mathematics behind SQL:
You need to see tables and queries as a set of data, with function as UNION and INTERSECT you are able to manipulate those sets.
In example:

A = {1,2,3}
B = {a,b,c}
C = {a,1,5}

D = A UNION B = {1,2,3,a,b,c}

There are more possible operations you can do on entity sets, but I think a UNION is the solution to your problem. 
SELECT column1, column2
FROM table1


SELECT column1,column2, column3
FROM table2

Pippo Foo, Jun 01, 2017
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas