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)
 Query Help

Author  Topic 

chetanb3
Yak Posting Veteran

52 Posts

Posted - 2009-02-13 : 06:39:50
Hi,

Is there any way that I can select many different data from different tables in one query without interfering each other?

For example,

Lets say that:

table1 has a COUNT(data) = 8
table2 has a COUNT(data) = 3
table3 has a COUNT(data) = 2

I want to select All columns form each of the tables as one result set. i tried by using full join on Guid, but it retuen duplicate rows that i don't want.



bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-13 : 06:47:34
use distinct
count(distinct data)
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2009-02-13 : 06:52:33
is there a connection between the tables?
How do you want the data presented?


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

chetanb3
Yak Posting Veteran

52 Posts

Posted - 2009-02-13 : 06:59:05
bklr-
I want to select columns and not count
nr-
these tables are linked by Guid. what do you mean by DTS could you please elaborate?
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2009-02-13 : 07:00:20
select t1.*, t2.*. t3.*
from
(select seq = row_number() over(order by guid), * from table1) t1
full outer join
(select seq = row_number() over(order by guid), * from table2) t2
on t1.seq = t2.seq
full outer join
(select seq = row_number() over(order by guid), * from table3) t3
on t1.seq = t3.seq or t2.seq = t3.seq

or maybe

select t1.*, t2.*. t3.*
from
table1 t1
full outer join
table2 t2
on t1.guid = t2.guid
full outer join
table3 t3
on t1.guid = t3.guid or t2.guid = t3.guid



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-13 : 07:05:22
quote:
Originally posted by chetanb3

Hi,

Is there any way that I can select many different data from different tables in one query without interfering each other?

For example,

Lets say that:

table1 has a COUNT(data) = 8
table2 has a COUNT(data) = 3
table3 has a COUNT(data) = 2

I want to select All columns form each of the tables as one result set. i tried by using full join on Guid, but it retuen duplicate rows that i don't want.






do you mean merging data as rows ir columns?
Go to Top of Page

chetanb3
Yak Posting Veteran

52 Posts

Posted - 2009-02-13 : 08:49:27
not exactly that
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-13 : 08:59:12
then show what you want by means of some sample data
Go to Top of Page

chetanb3
Yak Posting Veteran

52 Posts

Posted - 2009-02-18 : 08:37:49
Thanks nr your solution works for me.
Go to Top of Page
   

- Advertisement -