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 2000 Forums
 SQL Server Development (2000)
 Select Query

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2008-07-10 : 11:11:05
I need a query which should display the data in the results window.
The table in both database are same..

select colname from database1..tablex
select colname from database2..tablex

output:

DB1Colname DB2Colname
---------- ----------
12 12
13 13

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-07-10 : 11:15:14
select a.colname as DB1Colname, b.colname as DB2Colname
from database1..tablex a left join database2..tablex b on a.PK = b.PK


"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2008-07-10 : 11:29:27
Thanks jhocutt !!

I had a new reqs..I want to modifiy yr query for the counts.

select count(*)db1count from database1..tablex
select count(*)db2count from database2..tablex

output should be
:

DB1Count DB2Count
-------- ---------
5 5


Please suggests..
Thanks for your help in advance

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-10 : 14:27:15
[code]select db1count,db2count
FROM
(
select count(*) as db1count from database1..tablex)t1
INNER JOIN
(
select count(*) as db2count from database2..tablex)t2
ON 1=1[/code]
Go to Top of Page
   

- Advertisement -