For tables that are very long there is the option to have sticky headers that stay fixed as the user scrolls down the page. This helps the user not to lose context and avoids them having to scroll up in the page to verify the labels of the columns of the table.
The table header will stay sticky until the user scrolls past the last item of the table. If there is another table immediately after, the one above would stop being fixed once the last item of the table scrolls past it, and the following table header would then become sticky.
When using a fixed table header users will still be able to change the sorting of the table. When a user clicks on the label they want to start sorting by, the table will sort its contents whilst keeping the scroll position of the user. That means that changing the sorting wouldn’t scroll the user back to the top of the table, but instead the content would reorganise and it would be up to them to scroll back up if necessary.