x

Id matches same table different columns

 ID ID_1  ID_2 ID_3
 1 1 NULL 1
 2 1 2 1
 3 3 2 1
 4 3 3 NULL
 5 NULL  3 NULL
 6 NULL  NULL 6
 7 7 NULL 6
 8 7 8 NULL
 9 NULL  8 NULL

Hello,

Please refer the above

 ID    Related_ID
 1    1
 2    1
 3    1
 4    1
 5    1
 6    6
 7    6
 8    6
 9    6

The ID_1, ID_2 are the same ID as per first column but related....I need to produce a final output with min of related ID....

Please can you help me construct the query

Thanks

more ▼

asked Jul 13 at 12:19 PM in Default

avatar image

ashish420
1 1

Sorry the table was not pasted well

what I meant was that the table has ID ID_1 ID_2 ID_3 and so on

now ID 1 is related to ID 2 so will be captured as

ID ID_1
1 1 2 2

same goes on and finally I have to work out all that match each other

Thanks

Jul 13 at 12:26 PM ashish420

is this the desired output?

 ID ID_1
 1  1 2 2

It is not apparent to me from the question what the desired result is.

Jul 19 at 01:52 PM KenJ

This is the desired result

 ID    Related_ID
  1    1
  2    1
  3    1
  4    1
  5    1
  6    6
  7    6
  8    6
  9    6
Jul 19 at 02:51 PM ashish420

ID Related_ID 1 1 2 1 3 1 4 1 5 1 6 6 7 6 8 6 9 6

This is the desired result

Jul 19 at 02:51 PM ashish420

Sorry the format is not correct when pasted

please refer the image file

https://drive.google.com/open?id=0BxXB4ngfzwLTVVRlTU12NFRkSU0

the first part of table is input and second part is output

Jul 19 at 02:53 PM ashish420
show all comments (comments are locked)
10|1200 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x2152
x421

asked: Jul 13 at 12:19 PM

Seen: 40 times

Last Updated: Jul 19 at 05:16 PM

Copyright 2017 Redgate Software. Privacy Policy