Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Select statements in one Query in SQLite

Tags:

sqlite

Is it possible to run multiple select statements in one query in SQLite?

Such as:

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;

It gives me the error:

'Error while executing query: only a single result allowed for a SELECT that is part of an expression'

Is there something wrong with my expression or is this just not supported in SQLite?

Thanks

like image 700
TheGateKeeper Avatar asked Mar 06 '13 17:03

TheGateKeeper


1 Answers

Using the result of a subquery as a source table for further querying must be done in the FROM clause:

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

However, this would be a cross join, which is not what you want.

To just append multiple tables (with the same number of columns), use UNION ALL:

SELECT ChestGemEffects.Value,
       Effect.Name
  FROM ...
  ...
UNION ALL
SELECT WeaponGemEffects.Value,
       Effect.Name
  FROM ...
  ...
like image 142
CL. Avatar answered Sep 20 '22 14:09

CL.