Solved

Sql error, Incorrect syntax

Posted on 2007-11-30
4
280 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

13 Experts available now in Live!

Get 1:1 Help Now