I have created a the following view in my Database after combining multiple tables. A select * from MYViEW gives the following result below.
ProductID | TechID | ContactID | Priority | FIRSTNAME | MIDDLEINI | LASTNAME |
1123 2406 1371 1 Pradeep X Nayak
1123 2406 1368 2 Hello W World
1123 2406 1363 3 Foo Y World
1299 2279 1208 2 Some Z Dude
And I need the OUTPUT result to below to be displayed:
ProductID | TechID | ContactID | Priority | FIRSTNAME | MIDDLEINI | LASTNAME | Buyers |
1123 2406 1371 1 Pradeep X Nayak Nayak, Pradeep X; World, Hello W; World, Foo Y
1299 2279 1208 2 Some Z Dude Dude, Some Z
For every Product ID and Tech ID have a single record, and all the Buyers must be combined in a column in the format LastName, FirstName MiddleIni and each name separated by a space. I have already tried to use the custom aggregate function from here for combing the results to a single column. Please let me know if you can help me with a query for this.
This will display the data in the manner than you want:
see SQL Fiddle with Demo
This is getting the
MIN()priority value – the highest – and then theMAX()contactId