I have 2 tables, Header and Body, with the same columns and multiple groups of records. For each group, I want one record of header and the rest of the body records.
Header
Id Group Name Value
1 1 n1 v1
2 2 n2 v2
Body
Id Group Name Value
1 1 nb1 vb1
2 1 nb2 vb2
3 2 nb3 vb3
Expected Result
Id Group Name Value
1 1 n1 v1
2 1 nb1 vb1
3 1 nb2 vb2
4 2 n2 v2
5 2 nb3 vb3
If it was just one group I could have just done a union but the number of groups isn't fixed.
The Id
column in the result is just a row number. The other three columns Group
, Name
, and Value
are more important to me.
The header row is always the first row for that group.
Best Answer
I don't see why this won't work:
Results:
Also, don't use reserved keywords as column names, please!