Question

I have a question posted here:
java nested while loop in result set

and the answer is correct, but unfortunately my sql server doesn't support insensitive, updatable ResultSets (the error says "the cursor type/concurrency combination is not supported")

What is the best way to merge results from 2 result sets to get the merged result shown below.

ResultSet set1: 
id | name
1  | A
2  | B
3  | C
...

ResultSet set2:
id | alias
1  | F
2  | G
2  | H

I want to print out:

Id: 1, Name: A, Alias: F
Id: 2, Name: B, Alias: G, H

FYI, the id is in ascending orders in both sets. Both ResultSets are results returned from sql queries And I don't use UNION because the sql SELECT queries return different fields ('name' and 'alias')

Était-ce utile?

La solution

You could perform the following

Select s1.Id, s1.Name, s2.Alias
  from Set1 s1, Set2 s2
 where s1.Id= s2.Id
 order by s1.Id, s2.Alias

Or choose "Left Union" depending on whether you want to see the "C" row.
Now you will get:

 Id  Name  Alias
     1  A     F
     2  B     G
     2  B     H

I don't know of a way to get the multiple "Set2" rows into a single row

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top