Home  /  Questions  /  Question

0   0
May 31, 2017

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.

0   0
Jun 01, 2017
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

 1 comment
Something to think about, thank you for your input! --- David Arena  Jun 01, 2017