[Solved] query sql between two tables [duplicate]


Here’s how I’d go about it – I wrote it in SQL because I’m WAY better at that than I am at LINQ, but converting from one to the other should be straightforward:

select 
    t1.id
    , t1.value
from table1 as t1
    inner join table2 as t21
        on t21.idTable1 = t1.id
        and t21.number = 1
    inner join table2 as t23
        on t23.idTable1 = t1.id
        and t23.number = 3
    inner join table2 as t24
        on t24.idTable1 = t1.id
        and t24.number = 4

This joins to a subset of Table 2 three times, once for each value that you want. Using “inner join” makes the logic equivalent to an AND.

solved query sql between two tables [duplicate]