Paschal
Paschal

Reputation: 27

Inner Joins with where clause in SQL Server 2012

I have tried all answers but none are working. But the code is working when I use only one column either State or LGA. When I combine the two as you can find in the query below I get an error:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ','.

Please help me out

Code:

SELECT [Community].[CommunityID], 
       [Community].[CommunityName], 
       [Community].[StateID], 
       [StateName] AS [StateName], 
       [Community.LGAID], 
       [LGA].[LGName] AS [LGName] 
FROM [Community], [State] 
WHERE ([Community].[StateID] = [State].[StateID], [LGA] 
WHERE [Community].[LGAID] = [LGA].[LGAID]

Upvotes: 0

Views: 177

Answers (1)

Kannan Kandasamy
Kannan Kandasamy

Reputation: 13959

I think you are trying to do join and it is syntax error near to LGA, you can convert your code as below to provide explicit join conditions

SELECT [Community].[CommunityID], [Community].[CommunityName], [Community].[StateID], [StateName] AS [StateName], [Community].[LGAID], [LGA].[LGName] AS [LGName] 
FROM [Community] JOIN [State] ON [Community].[StateID] = [State].[StateID]
JOIN [LGA] ON [Community].[LGAID]=[LGA].[LGAID]

Upvotes: 1

Related Questions