Connecting to a Custom SQL Query

For most relational data sources you can connect to a specific query rather then the entire data source. Often this can be useful when you know exactly the information you need and you understand how to write SQL queries.
  1. Select Custom SQL in the connection dialog box.
  2. Type or paste the query into the text box. The button in the upper right corner of the text box opens a larger editing window for more complex queries.

When you finish the connection, only the relevant fields display in the Tableau Data window.
If your SQL query references duplicate columns, you may get errors when trying to use one of the columns in Tableau. This will happen even if the query is valid. For example, consider the following query:
SELECT * from authors, titleauthor where authors.au_id = titleauthor.au_id
The query is valid, but the au_id field is ambiguous because it exists in both the “authors” table and the “titleauthor” table. Tableau will connect to the query but you will get an error anytime you try to use the au_id field. That’s because Tableau doesn’t know which table you are referring to.

5 comments:

  1. This concept is a good way to enhance the knowledge.thanks for sharing. please keep it up salesforce Online Training Bangalore

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Hi, I would like to check if it is possible to restrict users' access to the original data sources e.g. two tables. Instead I will write a custom SQL that reads data from these two base tables to restrict the columns and also add some calculated fields. Is this possible?
    i.e. allow access to custom sql but not base tables in Tableau. Appreciate your sharing and advice. Thank you.

    ReplyDelete
  4. This blog gives very important info about Tableau Thanks for sharing Tableau Online Course

    ReplyDelete