I’m dealing with two tables named feature
and inspection
. I’m looking for assistance in constructing a SQL query that can retrieve the latest inspection record for every type of feature in its respective inspection category.
Here’s how my feature table is set up:
id | name
----|-----
1 | tree
2 | flower
And below is the structure of my inspection table:
id | feature_id | category | date_created
---|------------|-------------|-------------
1 | 1 | inspection | 10/10/2010
2 | 1 | cleaned | 10/20/2009
3 | 2 | inspection | 1/1/2008
4 | 1 | inspection | 1/1/2005
I need the result to reflect the most recent inspection for each feature across all inspection categories, in a format similar to this:
inspection_id | feature_id | date | category
---------------|------------|--------------|-----------
1 | 1 | 10/10/2010 | inspection
2 | 1 | 10/20/2009 | cleaned
3 | 2 | 1/1/2008 | inspection
What would be the best way to formulate this query? I’ve attempted to use GROUP BY but haven’t succeeded in getting the anticipated results.