Groups | Blog | Home
all groups > sql server mseq > february 2005 >

sql server mseq : Union Query syntax


Hoof Hearted
2/2/2005 1:43:01 AM
I want to pull the most recent record from 2 tables with a Union query.
Here's what I thought would work:

Select TOP 1 EntryTime, Windspeed, WindDirection, Temperature FROM
BlackpoolWeather ORDER BY EntryTime Desc
UNION Select TOP 1 EntryTime, Windspeed, WindDirection, Temperature FROM
ManchesterWeather ORDER BY EntryTime Desc

Hugo Kornelis
2/2/2005 10:07:52 PM
[quoted text, click to view]

Hi Hoof,

Try this:

SELECT EntryTime, Windspeed, WindDirection, Temperature
FROM (SELECT TOP 1 EntryTime, Windspeed, WindDirection, Temperature
FROM BlackpoolWeather
ORDER BY EntryTime DESC) AS a
UNION ALL
SELECT EntryTime, Windspeed, WindDirection, Temperature
FROM (SELECT TOP 1 EntryTime, Windspeed, WindDirection, Temperature
FROM ManchesterWeather
ORDER BY EntryTime DESC) AS b

Wouldn't your life become much easier with one table "Weather", with City
as an extra column, also part of the primary key?

Best, Hugo
--

AddThis Social Bookmark Button