SQLite中的一个Query中的多个Select语句

时间:2013-03-06 17:03:40

标签: sqlite

是否可以在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中是不支持的吗?

由于

1 个答案:

答案 0 :(得分:12)

使用子查询的结果作为源表进行进一步查询必须在FROM子句中完成:

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

然而,这将是cross join,这不是你想要的。

要添加多个表(列数相同),请使用UNION ALL

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