2015-07-10 119 views
0

我使用以下查詢從mysql表中檢索信息。將MySQL查詢轉換爲Informix

SELECT ACCESS_TOKEN, 
     AUTHZ_USER, 
     TOKEN_SCOPE, 
     TOKEN_STATE, 
     REFRESH_TOKEN_TIME_CREATED, 
     REFRESH_TOKEN_VALIDITY_PERIOD, 
     IDN_OAUTH2_ACCESS_TOKEN_SELECTED.TOKEN_ID 
FROM 
    (SELECT ACCESS_TOKEN, 
      AUTHZ_USER, 
      TOKEN_STATE, 
      REFRESH_TOKEN_TIME_CREATED, 
      REFRESH_TOKEN_VALIDITY_PERIOD, 
      TOKEN_ID 
    FROM IDN_OAUTH2_ACCESS_TOKEN 
    WHERE CONSUMER_KEY = "" 
     AND REFRESH_TOKEN = "" 
    ORDER BY TIME_CREATED DESC 
    LIMIT 1) AS IDN_OAUTH2_ACCESS_TOKEN_SELECTED 
    JOIN IDN_OAUTH2_SCOPE_ASSOCIATION 
WHERE IDN_OAUTH2_ACCESS_TOKEN_SELECTED.TOKEN_ID = 
IDN_OAUTH2_SCOPE_ASSOCIATION.TOKEN_ID; 

如何在具有相同表的Informix數據庫中獲得相同的結果?

+1

ANSI SQL需要對每個JOIN,但在這裏,你有一個相反。只要將最後的WHERE更改爲ON即可。 – jarlh

+0

它的工作,添加了一個答案。 –

回答

2

同樣可以通過將 'LIMIT 1' 到 'FIRST 1' 和 '位置' 的加入到 'ON' 來完成,

SELECT ACCESS_TOKEN, AUTHZ_USER, TOKEN_SCOPE, TOKEN_STATE, 
     REFRESH_TOKEN_TIME_CREATED, REFRESH_TOKEN_VALIDITY_PERIOD, 
     IDN_OAUTH2_ACCESS_TOKEN_SELECTED.TOKEN_ID 
    FROM (SELECT FIRST 1 ACCESS_TOKEN, AUTHZ_USER, TOKEN_STATE, 
       REFRESH_TOKEN_TIME_CREATED, REFRESH_TOKEN_VALIDITY_PERIOD, 
       TOKEN_ID 
      FROM IDN_OAUTH2_ACCESS_TOKEN 
     WHERE CONSUMER_KEY = "" AND REFRESH_TOKEN = "" 
     ORDER BY TIME_CREATED DESC) AS IDN_OAUTH2_ACCESS_TOKEN_SELECTED 
    JOIN IDN_OAUTH2_SCOPE_ASSOCIATION 
    ON IDN_OAUTH2_ACCESS_TOKEN_SELECTED.TOKEN_ID = IDN_OAUTH2_SCOPE_ASSOCIATION.TOKEN_ID;