我有兩個表充滿了客戶調查響應數據。我一直在分別對它們運行查詢,並在不到一秒鐘內返回結果,但如果將它們結合起來,它似乎永遠運行。 5分鐘以上沒有結果返回,沒有錯誤發生,它仍然顯然是「運行」,但我無法弄清楚它實際上試圖做什麼可能是如此複雜。聯盟/聯盟所有慢或不工作
從本質上說,我的查詢工作,分別是:
SELECT
oldsurveys.column1 as [something1],
oldsurveys.column2 as [something2],
oldsurveys.column3 as [something3],
'staticvalue1' as [something4],
oldsurveys.column5 as [something5]
FROM
database1.dbo.table1 oldsurveys
WHERE
oldsurveys.column1 = 'something'
AND oldsurveys.column2 >= '2014-01-01 00:00:00'
ORDER BY [something2], [something1]
SELECT
newsurveys.column1 as [something1],
newsurveys.column2 as [something2],
newsurveys.column3 as [something3],
newsurveys.column4 as [something4],
'staticvalue2' as [something5]
FROM
database2.dbo.table1 newsurveys
WHERE
newsurveys.column1 = 'something'
AND newsurveys.column2 >= '2014-01-01 00:00:00'
ORDER BY [something2], [something1]
如果我跑,我得到兩個數據表返回幾乎瞬間。如果我在兩個select語句之間添加UNION ALL
,請註釋掉第一個ORDER BY
並嘗試再次運行它只是運行並運行並運行,無結果...
任何想法我在做什麼錯?這些表是否在不同的數據庫中導致這種情況,如果是這樣,是否有解決方法?
執行計劃???? – 2014-09-04 16:03:07
如果您從兩者中刪除訂單,該怎麼辦? – Aret 2014-09-04 16:07:05
如果我完全刪除了'ORDER BY'子句,那麼它會很快得出第一個select語句的所有結果,然後第二個select語句(與它只是無限期地運行相同的問題)沒有任何結果。 – CactusCake 2014-09-04 17:46:46