On 2015-08-30 09:02 PM, Lev wrote: > Okay, it is more like an SQL question... > > So I have say three different SELECT on one table. I'd like to combine the > three to have data in the result, only if one particular field is the same for > each query.
Might I suggest 2 approaches: (I'm just making up the schema since you did not specify it, but if your schema is significantly more complex, post it and we can adapt to it). 1 - Sub-Queries: SELECT A.Data, B.Data, C.Data FROM (SELECT KeyField, Col1 AS Data FROM someTable WHERE Col1 > 5) AS A JOIN (SELECT KeyField, Col2 AS Data FROM someTable WHERE Col2 < 10) AS B JOIN (SELECT KeyField, Col3 AS Data FROM someTable WHERE Col3 = 20) AS C WHERE A.KeyField = B.KeyField AND B.KeyField = C.KeyField; 2 - Common table expression (CTE): WITH A(KeyField, Data) AS (SELECT KeyField, Col1 FROM someTable WHERE Col1 > 5), B(KeyField, Data) AS (SELECT KeyField, Col2 FROM someTable WHERE Col2 < 10), C(KeyField, Data) AS (SELECT KeyField, Col3 FROM someTable WHERE Col1 = 20) SELECT A.Data, B.Data, C.Data FROM A JOIN B ON B.KeyField = A.KeyField JOIN C ON C.KeyField = A.KeyField ; You could of course add lots of other columns, this just the minimum to make the idea work. HTH, Ryan > > I think this is possible with subquery and virtual tables, but I can't really > figure out the syntax. > > Any help are welcome. > > Thanks, > Lev >