Using Relationship Queries with History Objects

Custom objects and some standard objects have an associated history object that tracks changes to an object record. You can use SOQL relationship queries to traverse a history object to its parent object.

For example, the following query returns every history row for Foo__c and displays the name and custom fields of Foo:

1SELECT OldValue, NewValue, Parent.Id, Parent.name, Parent.customfield__c 
2FROM foo__history

This example query returns every Foo object row together with the corresponding history rows in nested subqueries:

1SELECT Name, customfield__c, (SELECT OldValue, NewValue FROM foo__history) 
2FROM foo__c