0

SQL

I think that my join statement is incorrect:

select distinct product.ID, 
product.externalid as 'Product ID', 
product.productname as 'Product Name', 
StaticSpec.StaticSpecGroupName as 'Static Spec Group Name',
StaticSpec.StaticSpecName as 'Static Spec Name',
StaticSpec.StaticSpecValue as 'Static Spec Value',
company.companyname as 'Buyer Site'

from Product 
join StaticSpec on Product.id = staticspec.ProductID,
join Company on company.id = product.id

where Product.active = 'Yes'

In order to get the Company Name in the Query I created the above, but I cannot get it to display correctly and none of my notes are helping at all. Are there any SQL gurus out there that might be able to see what is incorrect?

Thanks so much in advance!

7
  • 1
    You need to tell us more information. What should it look like? What does it look like? That said, keep an eye on your capitalisation. 'product' != 'Product' Commented Nov 13, 2013 at 15:59
  • 1
    Instead of displaying correctly, what is it displaying? What are the table definitions of Company and Product? Commented Nov 13, 2013 at 15:59
  • Like the other guys said, it's hard to tell without knowing the schema, but "company.id = product.id" does not look right to me Commented Nov 13, 2013 at 16:03
  • Should display Product ID, Product Name, Static Spec Group Name, Static Spec Name, and Static Spec Value. All of which was working correctly, however, I need to find out what company is assigned to them, so I added the Select Statement: company.companyname as 'Buyer Site'. Then I needed to join the company to the product using the 'Key', which is ID, so I then added the Join Statement: join Company on company.id = product.id, to which, now noting is displaying and the following error message is populating: Msg 156, Level 15, State 1, Line 11 Incorrect syntax near the keyword 'join'. Commented Nov 13, 2013 at 16:05
  • Ah, the syntax error is because of an errant comma after the first JOIN clause. Remove that comma. But then you'll get incorrect results because the condition company.id = product.id is almost certainly wrong. Commented Nov 13, 2013 at 16:06

1 Answer 1

1

You're joining on companyid = productID - presumable not the same thing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.