HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Using the result set of a select query as the input of another select

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
resultthequeryinputusinganotherselectset

Problem

I need to make three select queries over three different tables, using the outputs of each select query, the catch is each one gives multiple results. Here is how I do it.

Select "Title", "Num" from "Table" where "Id" in (

    Select "Id" from "Table2" where "Id"    in (

        select distinct "Id" from "Table3" where foo-clause         
           )

)


İt only gives me the result of one of the results. How can I make each one use multiple inputs?

Solution

You need to join the 3 tables together into one select rather then use the other two tables as part of a where clause. I have provided an example of joining all 3 together and having a condition for the third table.

SELECT a."Title", a."Num"
FROM   "Table" a,
       "Table2" b,
       "Table3" c
WHERE  a."Id" = b."Id"
AND    a."Id" = c."Id"
AND    c.foo-clause = foo-clause

Code Snippets

SELECT a."Title", a."Num"
FROM   "Table" a,
       "Table2" b,
       "Table3" c
WHERE  a."Id" = b."Id"
AND    a."Id" = c."Id"
AND    c.foo-clause = foo-clause

Context

StackExchange Database Administrators Q#203131, answer score: 2

Revisions (0)

No revisions yet.