I have a restaurants. So I have a “menu” table and an “orders” table. I want to find when a given dish was most recently ordered. So I know I have to use group by dishId at some point, but everything I try returns an error. The following query works, but it returns duplicates. I only want the most recent instance for each dish. Note that my “orders” table contains customer information that I am not presently interested in.
select o.timestamp, m.*
from orders o
inner join menu m
on (o.dishId = m.dishId);
I think the problem your having here is you need to include each of the columns you want to group by
If you want to group by more columns you have to add them in both places. Example: