Paulconsulting
asked on
sql server query grouping
I have a query that is returning the following data.
Broward County 07DB-3V-11-16-01-Z 08 596000531 Buyouts Null Null
Broward County 07DB-3V-11-16-01-Z 08 596000531 Null Null Buyouts
I would like to group it up to just show one line that looks like :
Broward County 07DB-3V-11-16-01-Z 08 596000531 Buyouts Null Buyouts
Thanks in advance.
Broward County 07DB-3V-11-16-01-Z 08 596000531 Buyouts Null Null
Broward County 07DB-3V-11-16-01-Z 08 596000531 Null Null Buyouts
I would like to group it up to just show one line that looks like :
Broward County 07DB-3V-11-16-01-Z 08 596000531 Buyouts Null Buyouts
Thanks in advance.
Here you can use Group By clause in SQL to combine result, you can apply group by on selected columns
ASKER
Grouping doesn't work for me in this scenario, at least not that I can tell. Do you have a query in mind?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SELECT name, id1, id2, MAX(buyout1) AS buyout1, MAX(buyout2) AS buyout2, MAX(buyout3) AS buyout3
FROM ...
GROUP BY name, id1, id2
Corresponds to sample data like this:
name = Broward County
id1 = 07DB-3V-11-16-01-Z 08
id2 = 596000531
buyout1 = Buyouts
buyout2 = Null
buyout3 = Null
...
buyout1 = Null
buyout2 = Null
buyout3 = Buyouts
FROM ...
GROUP BY name, id1, id2
Corresponds to sample data like this:
name = Broward County
id1 = 07DB-3V-11-16-01-Z 08
id2 = 596000531
buyout1 = Buyouts
buyout2 = Null
buyout3 = Null
...
buyout1 = Null
buyout2 = Null
buyout3 = Buyouts
ASKER
I resolved it, I inserted the results into a Temp table then joined on itself.