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 2008 Forums
 Transact-SQL (2008)
 Transact SQL

Author  Topic 

Dhanalakshmi
Starting Member

12 Posts

Posted - 2011-09-21 : 06:53:20
Hi,

How to interrelate two tables or two select statement results?

Table1:
jobid isduplicate duplicateof
324773362 1 324773379
324773365 0 0
324773366 1 324773371
324773367 1 324773368
324773368 0 0
324773369 1 324773368
324773370 0 0
324773371 1 324773365
324773379 0 0
324773380 0 0
324773398 0 0




Table2:
jobid IsDuplicate IsADuplicateOf
324773362 0 0
324773365 0 0
324773366 0 0
324773367 0 0
324773368 0 0
324773369 0 0
324773370 0 0
324773371 0 0
324773379 0 0
324773380 1 324773379
324773398 1 324773368


The result table like,

jobid isduplicate duplicateof
324773362 1 324773379
324773365 0 0
324773366 1 324773371
324773367 1 324773368
324773368 0 0
324773369 1 324773368
324773370 0 0
324773371 1 324773365
324773379 0 0
324773380 1 324773379
324773398 1 324773368


Can you please help me?


Thanks,
DIP

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-21 : 07:11:45
[code]select jobid,max(isduplicate),max(duplicateof)
from
(
select jobid, isduplicate, duplicateof
from table1
union all
select jobid, isduplicate, duplicateof
from table1
)t
group by jobid
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Dhanalakshmi
Starting Member

12 Posts

Posted - 2011-09-22 : 05:17:44
Hi,

It is working fine.
Thanks for your response.

Thanks,
DIP
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-22 : 12:13:14
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -