Solved

Sql error, Incorrect syntax

Posted on 2007-11-30
4
281 Views
Last Modified: 2010-03-20
Sql error, Incorrect syntax

HI,

I am working on SQL 2000

What is the problem in my below query.

error says

Server: Msg 170, Level 15, State 1, Line 12
Line 12: Incorrect syntax near 'id'.



SELECT DISTINCT
                      *
FROM        
      dbo.ProductSubType
            INNER JOIN
                      dbo.ProductSubTypeLink
                  ON dbo.ProductSubType.id = dbo.ProductSubTypeLink.ProductSubTypeId
            INNER JOIN
                      dbo.ProductSubCategoryLink
            INNER JOIN
                      dbo.Product
                  ON dbo.ProductSubCategoryLink.ProductID = dbo.Product.id
                  


Thanks
0
Comment
Question by:tia_kamakshi
  • 2
4 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 20380887
you are missing the join condition for the  dbo.ProductSubCategoryLink  table...


apart from that, note that you should consider using table alias names...
SELECT DISTINCT  *
FROM  dbo.ProductSubType pst
INNER JOIN dbo.ProductSubTypeLink  pstl
   ON pst.id = pstl.ProductSubTypeId 
INNER JOIN dbo.ProductSubCategoryLink pscl
   ON pscl..... = .....
INNER JOIN dbo.Product p
   ON pscl.ProductID = p.id

Open in new window

0
 
LVL 7

Expert Comment

by:Chandan_Gowda
ID: 20380898
You have joined  dbo.ProductSubCategoryLink table but u have not mentioned the column names
0
 
LVL 16

Expert Comment

by:Rick_Rickards
ID: 20383160
You're SELECT statement asks for everything * but that will error when everything could be from any one of several tables.  Your * needs to be preceeded by a table name from which you want values.  Also you can not use the * more than one time.

Also there is a missing JOIN in reference to the dbo.ProductSubCategoryLink table.... To make the two examples easier to see here is the before and after picture....

Before - Syntax Error

SELECT DISTINCT
                *
FROM        
      dbo.ProductSubType
            INNER JOIN dbo.ProductSubTypeLink ON dbo.ProductSubType.id = dbo.ProductSubTypeLink.ProductSubTypeId
            INNER JOIN dbo.ProductSubCategoryLink
            INNER JOIN dbo.Product ON dbo.ProductSubCategoryLink.ProductID = dbo.Product.id


AFTER -- Adjust the table with the * to match the one you want and verify that the link added "ON dbo.ProductCategoryLink.ProductCategoryLinkID = dbo.ProductSubTypeLink.ProductCategoryLinkID " fits your situation, (adjusting table names and field names to produce the desired JOIN.

SELECT DISTINCT
                dbo.ProductSubType.*
FROM        
      dbo.ProductSubType
            INNER JOIN dbo.ProductSubTypeLink ON dbo.ProductSubType.id = dbo.ProductSubTypeLink.ProductSubTypeId
            INNER JOIN dbo.ProductSubCategoryLink ON dbo.ProductCategoryLink.ProductCategoryLinkID = dbo.ProductSubTypeLink.ProductCategoryLinkID
            INNER JOIN dbo.Product ON dbo.ProductSubCategoryLink.ProductID = dbo.Product.id




SELECT DISTINCT
                dbo.ProductSubType.*
FROM        
      dbo.ProductSubType
            INNER JOIN dbo.ProductSubTypeLink ON dbo.ProductSubType.id = dbo.ProductSubTypeLink.ProductSubTypeId
            INNER JOIN dbo.ProductSubCategoryLink ON dbo.ProductCategoryLink.ProductCategoryLinkID = dbo.ProductSubTypeLink.ProductCategoryLinkID
            INNER JOIN dbo.Product ON dbo.ProductSubCategoryLink.ProductID = dbo.Product.id
0
 
LVL 16

Expert Comment

by:Rick_Rickards
ID: 20383169
**** Reposting my last post to eliminate the unintended duplication it had at the bottom of the post...

You're SELECT statement asks for everything * but that will error when everything could be from any one of several tables.  Your * needs to be preceeded by a table name from which you want values.  Also you can not use the * more than one time.

Also there is a missing JOIN in reference to the dbo.ProductSubCategoryLink table.... To make the two examples easier to see here is the before and after picture....

Before - Syntax Error

SELECT DISTINCT
                *
FROM        
      dbo.ProductSubType
            INNER JOIN dbo.ProductSubTypeLink ON dbo.ProductSubType.id = dbo.ProductSubTypeLink.ProductSubTypeId
            INNER JOIN dbo.ProductSubCategoryLink
            INNER JOIN dbo.Product ON dbo.ProductSubCategoryLink.ProductID = dbo.Product.id


AFTER -- Adjust the table with the * to match the one you want and verify that the link added "ON dbo.ProductCategoryLink.ProductCategoryLinkID = dbo.ProductSubTypeLink.ProductCategoryLinkID " fits your situation, (adjusting table names and field names to produce the desired JOIN.

SELECT DISTINCT
                dbo.ProductSubType.*
FROM        
      dbo.ProductSubType
            INNER JOIN dbo.ProductSubTypeLink ON dbo.ProductSubType.id = dbo.ProductSubTypeLink.ProductSubTypeId
            INNER JOIN dbo.ProductSubCategoryLink ON dbo.ProductCategoryLink.ProductCategoryLinkID = dbo.ProductSubTypeLink.ProductCategoryLinkID
            INNER JOIN dbo.Product ON dbo.ProductSubCategoryLink.ProductID = dbo.Product.id
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ms sql stored procedure 22 88
SQL Stored Procedure insert running but not inserting record 40 62
MySQL left join performance 4 30
Substring() and LEFT() syntax 4 21
Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now