![]() ![]() SELECT * FROM Orders LEFT JOIN Products ON Orders. We could create a Products.category filter with a basic input variable, like so: Let’s say we want to create a SQL question that grabs all the orders from the Orders table, but we want to give people the option to filter the results by category in the Products table. We’ll use the Sample Database included with Metabase to add a filter widget with a dropdown menu to a question written in SQL. Creating a SQL filter widget with a dropdown menu Point #3 can be especially confusing, so let’s unpack it with an example. This allows the code to account for multiple selections people make in the filter widget. You simply supply a Field Filter to a WHERE clause (without a column or operator) and the Field Filter will manage the SQL code for you. Field Filters use a special syntax so they can handle SQL code behind the scenes.And depending on the database you’re using, you may need to include the full schema path in the FROM clause. Since Field Filters rely on metadata about columns in your tables (and the specific names of those tables), the filters can’t “know” that you’ve aliased a table. Field Filters won’t work with table aliases.You do, however, have the option to require a value. If no value is given, the SQL query will run as if the Field Filter didn’t exist. Field Filters are optional by default.Distinguishing Field Filters from simple Text, Number, and Date variables This article will go through Field Filters in depth, but first let’s discuss the main differences between Field Filter variables and basic Text, Number, and Date variables. However, Field Filters are well worth learning, as you can use them to create much more sophisticated filter widgets. To create a Field Filter, add a variable to your SQL code by enclosing the variable in double braces (Mustache style), and select Field Filter as the Variable type from the Variables sidebar.įield Filters can initially confuse some people, because they only work with certain fields, and people expect them to behave like basic input variables (which they don’t). ![]() To create “smarter” filter widgets that can display options specific to the data in the filtered columns, such as to create a dropdown menu of values, we can use a special variable type called a Field Filter. A Field Filter is a special type of variable that can wire up a variable in your SQL code to a field (column) in a table, which enables it to create a 'smart' filter widget.įor Metabase questions written in SQL, we can use basic variable types-Text, Number, and Date-to create simple SQL filter widgets. This article shows how to add smart SQL filter widgets to your native queries in Metabase using a special type of variable called a field filter. Learn more about SQL filters and variables.Only certain fields are compatible with Field Filters.Omit the direct assignment in the WHERE clause.Field Filters are incompatible with aliasing.Creating sophisticated SQL filter widgets for date fields. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |