Here's a SQL query that selects all of the unique month and year values from every instance of the class Post, which has a property, Date:
$months = DB::query("SELECT DISTINCT DATE_FORMAT(`Post`.`Date`, '%M') AS `Month`, DATE_FORMAT(`Post`.`Date`, '%Y') AS `Year` FROM `Post` ORDER BY `Post`.`Date` DESC");
I’d like to refine this query to include only Posts that are children of the Page running the query. Something like the following (except this doesn't actually work):
$months = DB::query("SELECT DISTINCT DATE_FORMAT(`Post`.`Date`, '%M') AS `Month`, DATE_FORMAT(`Post`.`Date`, '%Y') AS `Year` FROM `Post` ORDER BY `Post`.`Date` DESC, WHERE parentID = '". $this->ID . "' ");
What's the correct syntax?