This task can be performed using SheetQuery
Run SQL on Google Sheets
Best product for this task

SheetQuery
analytics
SheetQuery is the add-on that lets you run SQL directly on your spreadsheets. Combine the flexibility of Google Sheets with the power of SQL to analyze, update, and manage data like never before.

What to expect from an ideal product
- Adds SQL capabilities right inside Google Sheets without moving your data elsewhere
- Lets you combine data from multiple sheets using JOIN operations
- Filters and sorts data using familiar SQL WHERE and ORDER BY clauses
- Creates new sheets with query results automatically
- Updates existing data through SQL commands like UPDATE and DELETE