I want to perform a select which returns a few columns of data, and then also a nested table of related rows from another table (actually the same table joined on itself but I think this is irrelevant).
So the data is something like this:
id name registered
1 Dan N
2 Bill N
3 Bob N
4 Dan N
5 Bill Y
6 Dan Y
The idea is to perform a select which finds all the unregistered people who could be related to a registered account.
So the result would look like
registered.id name notreg.id name
5 Bill 2 Bill
6 Dan 1 Dan
4 Dan
I can handle all the selection criteria etc, and have a query that returns a normal inner join that finds this, but want to know if it’s possible to get a result set kind of like this, so no repeated values on the left side?
You’re probably better off suppressing duplicates in the Client (for example in Jasper Reports uncheck
Print Repeated Valueor in the XML setisPrintRepeatedValues="false")However on anything that supports a
WITH(CTE) andROW_NUMBER()(e.g. Oracle, SQL Server 2005+) .See working example
If you don’t have WITH and ROW_NUMBER you can do this
See working example