I have a table with different offers which are bound to a specific date. depended on the date the price changes. i want to get the cheapest deal for each date.
my problem is i use a group by like:
select price, date from deals group by date, price
to display the offer, i need more records which are not in the group by clause. the best field would be my autoid, so if a customer selects a offer with a specific price i can display this offer with all its fields using a second select.
i hope this makes it simpler to answer my question. i tried to keep it generic as possible but i have the feeling it was not described clear enough 🙂
Just add the
Idcolumn into theGROUP BYlistOtherwise Sql Server was not able identify which id is to return for grouped by price and date rows, for instance consider two following rows:
Which
Idvalue should be selected for row which is grouped by date and price?