Let’s say that I have two tables in a database: Table1 and Table2.
Table1 have the following columns:
Var1 | Var2
and Table2 have the following columns:
Var3 | Var4
I also have a constant, x.
Now, I would like to write an SQL expression that includes every row in Table1 that satisfies the following criteria:
Var1 = x
or there is a row in Table2 where Var4=Var2 and where Var3=x
How do I write this as an SQL expression?
I guess it should start with SELECT * FROM Table1 WHERE Var1=x but from there, I’m lost.
The magic element that you need is a UNION, which essentially appends one result set to another.