I have two tables as follows:
Customer | Product
------------------
A | Car
A | Bike
A | Boat
B | Foo
B | Bar
Customer | Friends
------------------
A | John
A | Andrew
B | Baz
For each customer I want to display a list of products purchased, and a list of friends like this:
Customer Products Friends
------------------------------
A - Car - John
- Bike - Andrew
- Boat
------------------------------
B - Foo - Baz
- Bar
If I use a normal JOIN then I get a list of friends for every separate product. I just want the two lists once.
The output lists with ‘-‘ need not be table cells, they can be <ul>s.
How can I achieve this? I would like to bind to ASP.net GridView. Should I try to do it all in one query, or use multiple queries and somehow add them both to the same Grid?
Each row actually forms part of a long report. Essentially each row of the report contains Customer ID, a bunch of other fields which match one-to-one with Customer ID, then the two lists for each Customer ID I described. Perhaps I can use a separate query for each list, then manually add each list to the grid on RowDataBound or similar?
You need 2 separate queries since you just want the list of data in 2 tables (with same where condition)
What SQL engine are you using?