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.

16 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. 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
  3. This comment has been removed by the author.

    ReplyDelete
  4. Wow,I think this is a very good and informative post about Tableau.

    Tableau Rest Api Connection

    ReplyDelete
  5. Hey there, thanks for sharing this informational article. If you are looking for ways to learn tableau then click here to find out how.

    ReplyDelete
  6. Really thanks for posting such an useful and informative stuff..

    Salesforce Training Online

    ReplyDelete
  7. Thanks for your valuable information. Its very good article.
    servicenow training
    servicenow certification

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

    ReplyDelete
  9. Thank you for sharing wonderful information with us to get some idea about it.

    tableau online training

    ReplyDelete
  10. Hi, I read your whole blog. This is very nice. Good to know about the career in. Python Training & Certification , anyone interested can Python Training for making their career in this field.

    ReplyDelete