nordin craft nordin craft - 3 years ago 143
SQL Question

How to combine 2 SQL queries?

I have this my first query:

SELECT (Temperature) + 273.15 FROM tbl_Temperature;


(
Temperature
is the column name and
tbl_Temperature
is the table name.)

Data in database
dbTemp
:

25,3
26,7
28,4


(This are Temperature in Celsius)

output
272,45
273,85
275,55


(this are temperature in Kelvin)

This is my second query:

SELECT MAX (Temperature) FROM tbl_Temperature;


Data in database
dbTemp
:

25,3
26,7
28,4


Output

28,4


(This are Temperature in Celsius)

I want to combine these queries.

Data in database
dbTemp
:

25,3
26,7
28,4


(This are Temperature in Celsius)

Desired output

272,45
273,85
275,55

max: 275,55


(This are temperature in Kelvin)

So what I want is that it shows the data in
Kelvin
and the maximum in
Kelvin
.

Answer Source

You simply need to do:

SELECT Temperature + 247.15  FROM tbl_Temperature;
UNION ALL
SELECT  'max: ' + cast(MAX (Temperature)+ 247.15 as nvarchar)  FROM tbl_Temperature;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download