2013-03-06 58 views
4

是否有可能在SQLite中的一個查詢中運行多個select語句?SQLite中一個查詢中的多個Select語句

如:

SELECT ( 
      SELECT ChestGemEffects.Value, 
        Effect.Name 
      FROM ChestGemEffects 
        INNER JOIN Effect 
          ON ChestGemEffects.EffectId = Effect.Id 
        INNER JOIN Gems 
          ON ChestGemEffects.GemId = Gems.Id 
      WHERE (Gems.[Key] = 'SG1') 
     ) 
     AS ChestEffects, 
     ( 
      SELECT WeaponGemEffects.Value, 
        Effect.Name 
      FROM WeaponGemEffects 
        INNER JOIN Effect 
          ON WeaponGemEffects.EffectId = Effect.Id 
        INNER JOIN Gems 
          ON WeaponGemEffects.GemId = Gems.Id 
      WHERE (Gems.[Key] = 'SG1') 
     ) 
     AS WeaponEffects, 
     ( 
      SELECT OthersGemEffects.Value, 
        Effect.Name 
      FROM OthersGemEffects 
        INNER JOIN Effect 
          ON OthersGemEffects.EffectId = Effect.Id 
        INNER JOIN Gems 
          ON OthersGemEffects.GemId = Gems.Id 
      WHERE (Gems.[Key] = 'SG1') 
     ) 
     AS OthersEffects; 

它給我的錯誤:

「錯誤而執行查詢:只允許一個SELECT單個結果是表達式的一部分」

是我的表達有什麼問題,或者只是在SQLite中不支持?

感謝

回答

10

使用子查詢作爲進一步查詢源表的結果必須在FROM子句中完成:

SELECT * FROM (SELECT ...), (SELECT ...) 

然而,這將是一個cross join,這是不是你想。

要只是追加多個表(使用相同的列數),使用UNION ALL

SELECT ChestGemEffects.Value, 
     Effect.Name 
    FROM ... 
    ... 
UNION ALL 
SELECT WeaponGemEffects.Value, 
     Effect.Name 
    FROM ... 
    ... 
+0

感謝您的答覆,但我決定派遣一個不同的查詢每個選擇。 – TheGateKeeper 2013-03-07 09:56:35