Custom SQL Queries in Tableau

Connecting to big databases can slow Tableau down significantly since it can take quite a long time to run the calculations. Since the speed of Tableau is one of the reasons why it is so fun to work with, this is quite annoying. Therefore filtering the data before working with it to create visualizations is often a good idea.

Tableau offers the option to use custom SQL queries when you are connected to a database. Then you can pull the data needed from a database, instead of using every single row of the data. At the bottom left corner of the data pane the option to write a custom SQL query pops up, once you are connected to the database (Fig. 1).

Figure 1: Pull data from a database using a custom SQL query.

Here you can write a simple SQL statement to select the data you want to extract.

Figure 2: Use a SQL query to only work with the data you need.

This also allows you to build up your Data Model in a different way. You can either load in joined tables using SQL or you load them in separately and then connected them individually within Tableau. Which may let you leverage the relationship advantages.

There is also the possibility to add a parameter to the SQL queries, which allows you to create more flexible data requests (Fig. 3).

Figure 3: Parameters within queries increase flexibility.

Once you have your connection and query set up, you can also use an extract, while working on the sheet, as the data won't need to be reloaded from the database constantly.

Author:
Frederik Egervari
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2025 The Information Lab