Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query for Join

Status
Not open for further replies.

angjbsca

Programmer
May 26, 2006
30
PR
I need to take data from one table then take data from other table and then join the 2 results.

ej..
select f1,f2,f3,f4 from t1 where f1<= date and f2 > date
select f1,f2,f3,f4 from t2 where f1<= date and f2 > date
select a.*,b.* from t1 a
left join t2 b
on a.f3 = b.f3
where b.f3 is null

Its is posible to do that in one query I need for reporting services matters.

 
Is it UNION that you want to do?

Code:
select f1,f2,f3,f4 from t1 where f1<= date and f2 > date

Union

select f1,f2,f3,f4 from t2 where f1<= date and f2 > date

Union will only work if the fields from both tables match. More specifically, each query must return the same number of fields and the data types for each field must match.

There is a difference between Union and Union All. Union will preform a Distinct for you, union all will return all the data (even if there would be duplicate records between the 2 tables).

I hope this helps.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top