docs/versioned_docs/version-2.61.0/how-to/delete-multiple-rows-table.md
This guide explains how to delete multiple rows from a table, assuming you've already connected to a data source. We'll use PostgreSQL for this example, but you can adjust the queries based on the SQL database that you are using.
</div> <div style={{paddingTop:'24px', paddingBottom:'24px'}}>SELECT * FROM tooljet // replace tooljet with your table name
Run the query on application load? option to execute the query automatically when the application starts.Data property and set the value to {{queries.getRecords.data}}.Bulk selection option.const uniqueIdentifier = "id";
const idsToDelete = Object.values(components.table1.selectedRows).map(dataUpdate => dataUpdate[uniqueIdentifier]);
const idsString = idsToDelete.map(id => `'${id}'`).join(', ');
const SQL = `DELETE FROM tooljet WHERE ${uniqueIdentifier} IN (${idsString});`;
return SQL;
The above code generates a SQL query that deletes rows from the database table where the id field matches the selected IDs in ToolJet's Table component.
If you're using a different column as the unique identifier, feel free to update the code accordingly. You can also update the Table name if you have renamed it, the default name is table1.
delete, and select SQL mode.{{queries.runjs1.data}}
In this query, we are dynamically loading the SQL statement generated by the JavaScript query.
<div style={{textAlign: 'left'}}> </div> </div> <div style={{paddingTop:'24px', paddingBottom:'24px'}}>Button text property to "Delete selected".{{queries.delete.isLoading || queries.getRecords.isLoading}}
Now, whenever you click on the Button component, the runjs1 query will run and generate a delete SQL statement with selected rows on the table. Once the runjs1 query executes, the delete query will execute and delete the rows from the database.
By implementing this, we are ensuring that every time rows are deleted, the Table component will automatically refresh to display the most recent data fetched from the database.
</div>