Magento 2 Collection is powerful. You can create custom entities and extend the default Magento capabilities. I am using this cheat sheet to record commonly use code sample. So, every time I need it I know where to look for. Please note that I haven’t detailed the solutions here as this is only a quick reference.
Get the First and last item from a Magento 2 Collection
In some cases, you will have to get the first or last element of a collection. This can be a product, category or your custom collection. it is always good practice to check the size of the collection before you apply getFirstItem() or getLastItem().
$data = $collection->getFirstItem();
Get Order Items from Order Item Collection
Programitically get Magento Sales Order Items without going through sales oders.
$orderItems = $this->_orderItemCollection->create();