In the following sections, some other advanced SQL techniques will be introduced:
DISTINCT ONclause, which helps finding the first records in groups
LATERALjoins, which allow subqueries to reference each other
Quite often it is necessary to find the first records based on some criteria. For example, let's take the
car_portal database; suppose it is required to find the first advertisement for each
car_id in the
Grouping can help in this case. It will require a subquery to implement the logic:
SELECT advertisement_id, advertisement_date, adv.car_id, seller_account_id FROM car_portal_app.advertisement ...