8

是否可以在 SQLite 的一个查询中运行多个选择语句?

如:

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 不支持?

谢谢

4

1 回答 1

23

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

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

但是,这将是一个cross join,这不是您想要的。

要仅附加多个表(具有相同数量的列),请使用UNION ALL

SELECT ChestGemEffects.Value,
       Effect.Name
  FROM ...
  ...
UNION ALL
SELECT WeaponGemEffects.Value,
       Effect.Name
  FROM ...
  ...
于 2013-03-06T17:34:20.220 回答