简体   繁体   中英

SQL JOIN Syntax Error in Tableau

I am in the process of writing a SQL query to join 5 different tables in Tableau (a data analytics software). Tableau keeps telling me I have a syntax error in my join operation and I cannot figure out where it may be. Here's the error I'm receiving along with my custom SQL query:

Database error

0x80040E14: Syntax error in JOIN operation.

The query:

SELECT TOP 1 * FROM (

[Attributes$].[Cache] AS [Cache],
[Attributes$].[Design Application] AS [Design Application],
[Attributes$].[Detailed Product Name] AS [Detailed Product Name],
[Attributes$].[Discs] AS [Discs],
[Attributes$].[Drive Height] AS [Drive Height],
[Attributes$].[Form Factor] AS [Form Factor],
[Attributes$].[Heads] AS [Heads],
[Attributes$].[Interface] AS [Interface],
[Attributes$].[Internal Product Name] AS [Internal Product Name],
[Attributes$].[Market Segment Desc] AS [Market Segment Desc],
[Attributes$].[Model] AS [Model1],
[Attributes$].[Product Family Desc] AS [Product Family Desc],
[Attributes$].[Product Mktg Name] AS [Product Mktg Name],
[Attributes$].[Product Type] AS [Product Type],
[Attributes$].[ST Model] AS [ST Model],
[Attributes$].[Sub Market Segment Desc] AS [Sub Market Segment Desc],
[Measures$].[Channel Type] AS [Channel Type],
[Measures$].[Cust Group Desc] AS [Cust Group Desc],
[Measures$].[Cust Sub Group Desc] AS [Cust Sub Group Desc],
[Measures$].[Fiscal Quarter] AS [Fiscal Quarter],
[Measures$].[Fiscal Week] AS [Fiscal Week],
[Measures$].[Fiscal Year] AS [Fiscal Year],
[Measures$].[Model] AS [Model (Measures)],
[Measures$].[Net Revenue] AS [Net Revenue],
[Measures$].[Region] AS [Region],
[Measures$].[Scenario] AS [Scenario],
[Measures$].[Standard Cost Mfg] AS [Standard Cost Mfg],
[Measures$].[Standard Cost Qty] AS [Standard Cost Qty],
[eFBC$].[Model] AS [Model2],
[eFBC$].[Int] AS [Int],
[eFBC$].[FY] AS [FY],
[eFBC$].[Q] AS [Q],
[eFBC$].[eFBC] AS [eFBC],
[Theater$].[Customer Sub Grp Code Numeric] AS [Customer Sub Grp Code Numeric],
[Theater$].[Forecast Region] AS [Forecast Region],
[Encryption$].[Encrypt Type] AS [Encrypt Type],
[Encryption$].[Model] AS [Model3]

FROM ( ( [Attributes$]
  LEFT JOIN [Measures$] ON [Attributes$].[Model] = [Measures$].[Model] )  
  LEFT JOIN [Encryption$] ON [Attributes$].[Model] = [Encryption$].[Model] )
FROM ( ( [Measures$]
  LEFT JOIN [eFBC$] ON ([Measures$].[Model] = [eFBC$].[Model]) AND ([Measures$].[Fiscal Year] = [eFBC$].[FY]) AND ([Measures$].[Fiscal Quarter] = [eFBC$].[Q] ) 
  LEFT JOIN [Theater$] ON ([Measure$].[Cust Sub Group Desc] = [Theater$].[Customer Sub Grp Code Numeric] ) )
FROM ( [eFBC$]
  LEFT JOIN [Encryption$] ON ([eFBC$].Model] = [Encryption$].[Model] ) ) )

) [CustomSQLQuery1]

Well. Broad advice. Don't use Custom SQL unless you can't do what you want with Tableau custom joins AND you are absolute sure of what you are doing.

It seems you're attempting to perform some very simple LEFT JOINs. Use Tableau default tool to do that, it is very simple, drag and drop, and very easy to visualize what is going on. You just drag the tables to the workplace, select the type of JOIN and the keys.

Back to your query, it is very wrong. Please go back to the basics and get it right. 1 SELECT to 1 FROM, listen to @Turophile. If you want to build temp tables, you need more SELECT FROM, but the proportion is always 1 to 1. And guess what, you don't need them in your example.

Apart from that, you either SELECT * or name the fields one by one.

Last, I don't think you can do TOP X on Tableau custom query. That's a decision they've made, not allow filters on the query itself, just after data is pulled. I personally don't like the restriction, but don't hate it as well.

Your query should be (did the SELECT * thing, you can replace * by all the field names text you have)

SELECT * FROM [Attributes$]
  LEFT JOIN [Measures$] ON [Attributes$].[Model] = [Measures$].[Model] )  
  LEFT JOIN [Encryption$] ON [Attributes$].[Model] = [Encryption$].[Model] )
  LEFT JOIN [eFBC$] ON [Measures$].[Model] = [eFBC$].[Model] AND [Measures$].[Fiscal Year] = [eFBC$].[FY] AND [Measures$].[Fiscal Quarter] = [eFBC$].[Q] 
  LEFT JOIN [Theater$] ON ([Measure$].[Cust Sub Group Desc] = [Theater$].[Customer Sub Grp Code Numeric]
  LEFT JOIN [Encryption$] ON ([eFBC$].Model] = [Encryption$].[Model]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM