Reputation: 3103
I have got two tables say tableA and tableB. Both tables have fileds say pointA and pointB. I need a single query to find the highest and lowest value among the columns pointA and pointB.
tableA
idA pointA
1 20
2 12
3 41
4 8
tableB
idB pointB
1 24
2 74
3 2
4 16
I want to get the result like this
HIGHEST LOWEST
74 2
Upvotes: 2
Views: 484
Reputation: 4610
select max(pointB) AS result from tableB
union
select min(pointA) AS result from tableA
Upvotes: 1
Reputation: 57573
Try:
SELECT MAX(point) as HIGHEST, MIN(point) as LOWEST
FROM
(SELECT pointA as point FROM tableA
UNION
SELECT pointB as point FROM tableB) t
Upvotes: 4
Reputation: 115530
SELECT MAX(high) AS highest
, MIN(low) AS lowest
FROM
( SELECT MAX(pointA) AS high
, MIN(pointA) AS low
FROM tableA
UNION ALL
SELECT MAX(pointB)
, MIN(pointB)
FROM tableB
) AS tmp
Upvotes: 1