从两个表中选择数据并按日期排序

CSS*_*ell -2 sql sql-server union select

I have two tables with data and need to combine them and order by date. I have the below query but the union keeps giving me an error.

SELECT 

AssetTitle,
AssetDate,
AssetTeaser,
AssetLink

FROM pressAssets WHERE AssetType=1 ORDER BY AssetDate ASC

UNION ALL

SELECT

BlogTitle,
BlogDate,
BlogEntry,
BlogLink


FROM

blogTempTable ORDER BY BlogDate ASC, AssetDate ASC;
Run Code Online (Sandbox Code Playgroud)

Can anyone help me with this?

Yuc*_*uck 5

Your code doesn't work as is. This will get you a result set, but the date fields all get merged together; you can't distinguish the source after the UNION is applied.

SELECT 
  Title,
  Date,
  Teaser,
  Link

FROM (
SELECT 

AssetTitle Title,
AssetDate Date,
AssetTeaser Teaser,
AssetLink Link

FROM pressAssets WHERE AssetType=1 

UNION ALL

SELECT

BlogTitle Title,
BlogDate Date,
BlogEntry Teaser,
BlogLink Link


FROM

blogTempTable) T

ORDER BY Date ASC;
Run Code Online (Sandbox Code Playgroud)