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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Cross joins

Author  Topic 

smitha
Posting Yak Master

100 Posts

Posted - 2010-01-08 : 05:14:52
I am having 2 tables with the same date and time. I am using cross joins to join the 2 tables. For each date and time, I am clubbing the values of both the tables.

ex: table1
6:00:00 am tag1 = 45, tag2= 34

table2
6:00:00 am tag3 = 12, tag4=78

Now I am joining table1 and table2 and the result should be

6:00:00 am tag1,tag2,tag3,tag4

but I am getting the result as

6:00:00 am tag1,tag2,tag3,tag4
6:00:00 am tag1,tag2,tag3,tag4

The answers are getting multipled.
can anyone help on this


Smitha

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-01-08 : 05:19:57
select t1.time_col,tag1,tag2,tag3,tag4 from table1 t1 inner join
table2 t2 on t1.time_col=t2.time_col

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

smitha
Posting Yak Master

100 Posts

Posted - 2010-01-08 : 06:20:58
Thanks I was able to get the result

quote:
Originally posted by senthil_nagore

select t1.time_col,tag1,tag2,tag3,tag4 from table1 t1 inner join
table2 t2 on t1.time_col=t2.time_col

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/




Smitha
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-08 : 07:22:46
quote:
Originally posted by smitha

I am having 2 tables with the same date and time. I am using cross joins to join the 2 tables. For each date and time, I am clubbing the values of both the tables.

ex: table1
6:00:00 am tag1 = 45, tag2= 34

table2
6:00:00 am tag3 = 12, tag4=78

Now I am joining table1 and table2 and the result should be

6:00:00 am tag1,tag2,tag3,tag4

but I am getting the result as

6:00:00 am tag1,tag2,tag3,tag4
6:00:00 am tag1,tag2,tag3,tag4

The answers are getting multipled.
can anyone help on this


Smitha


Why did you use Cross join? Do you know what it does?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -