Fetch and Filter data in SQL
This guide shows you how to retrieve and filter data by using a variety of SQL clauses.
Prerequisites
App Connected to PostgreSQL datasource.
When prepared statements are enabled and widget bindings are used, quotes are not required.
Using WHERE Clause
The WHERE clause in SQL filters data based on specific conditions, enabling you to retrieve rows that match your criteria.
Example 1: If you want to filter Table data based on specific criteria, such as gender, you can use a Select widget with the required option.
Configure the query to fetch data using selectedOptionValue reference property, like:
-- With prepared statements enabled
SELECT * FROM users WHERE gender = {{Select1.selectedOptionValue}};
Learn more about Server-side Filter on Table.
Example 2: If you want to create a dynamic WHERE clause query that depends on user input, such as allowing users to specify a name using an Input widget, prepared statements can't be effectively used in these cases because the structure of the query is not static.
- Configure the query to fetch data using text reference property, like:
-- With prepared statements disabled
SELECT * FROM users WHERE {{ Input1.text ? "name = '" + Input1.text + "'" : "1=1" }}
- Turn Off the Prepared Statements.
Learn more about Prepared Statements.
- Using the
IS
keyword in MySQL is not supported in Appsmith. Use the=
operator instead. true
/false
values should be without quotes i.e.{{true}}
instead of{{”true”}}
.