Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 join two fact tables

Author  Topic 

santana
Yak Posting Veteran

72 Posts

Posted - 2010-08-05 : 09:26:30
Hi,

I have two fact tables.
And I need to see the all data for both.
But I need to group by the columns what exist in both tables, without lost the others columns.
(like two outer joins, for both sides)
How can I do this? What type of join can I use?

Many Thanks!

Regards

santana

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-08-05 : 09:30:58
Try:
select ... from table1
UNION
select ... from table2

UNION will not return duplicate rows except they have a column with different values.

If that isn't what you want then give table structure, example data and wanted result.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ewomack
Starting Member

33 Posts

Posted - 2010-08-05 : 09:39:09
If you need to group the results, then you'll want to use a join. To see everything you can use a FULL join that will return everything from both tables and allow grouping on the results.

I think this is what you need, but can you give data samples to confirm?

Ed Womack
www.getmilked.com
Go to Top of Page

santana
Yak Posting Veteran

72 Posts

Posted - 2010-08-05 : 09:42:37
Ok.
But with union, I need to have the same colums, yes?

Fact A:

cod cod2 valueA date
100 xxx 10 201108
101 xxx 30 201108
103 yyy 40 201108

Fact B

cod2 valueB date
xxx 100 201108
yyy 200 201108

If I use union for this two tables, I will lost the infoamrtion about cod, yes?

Thank you for your help!!!

Regards,

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-08-05 : 09:45:49
What should be the output in relation to your sample data?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ewomack
Starting Member

33 Posts

Posted - 2010-08-05 : 09:54:14
Yes, union requires having the same columns, or at least heavily compatible columns. It's unclear to me whether you need a union or a join, but it sounds more like you need a join.

Ed Womack
www.getmilked.com
Go to Top of Page

santana
Yak Posting Veteran

72 Posts

Posted - 2010-08-05 : 10:24:38
I think I need a join, but I cant exclude any register......

????

thank you!
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-08-05 : 10:53:47
Please refer to this link and restate your question

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page
   

- Advertisement -