So sorry but I am new to SQL querying and could use a little help.
I will like to join results from 2 tables and I can’t seem to get it return results I need.
Query 1
select c1,c2,c3,c4,c5,c6,c7 from t1 where (c3 between cast(dateadd(day, -1,Getdate()) AS Date and cast(dateadd(day,0,getdate()) as date))
Query 2
select c1,c2,c3,c4,c5,c6 from t2 where c2 in ('user', 'connected', 'agent') and (c3 between cast(dateadd(day, -1,Getdate()) AS Date and cast(dateadd(day,0,getdate()) as date))
I tried using union all but I get an error must have equal number of expressions in their target lists.
Any assistance will be appreciated.
Advertisement
Answer
When using an union, both queries must have the same number of fields in the select statements. Query 1 has 7 items while query 2 has 6. You can add a null value to query 2.