Reputation: 4540
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
Upvotes: 9
Views: 34667
Reputation: 180310
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 ...
...
Upvotes: 26