Frits Verstraten
Frits Verstraten

Reputation: 2179

Inner join statement does not seem to work

I have a simple SQL statement that does not seem to work. I want the of table match_team ("match_id") on the table match ("id").

Therefore I wrote the following INNER JOIN STATEMENT

 SELECT * FROM match_team INNER JOIN match ON match_team.match_id = match.id

This throws an error however. Any thoughts on what might go wrong here?

Upvotes: 1

Views: 52

Answers (5)

Sajed.Golabpars
Sajed.Golabpars

Reputation: 1

First Of all check that you are using your database not the "Master" database ...

use Ctrl+u to access available databases dropdownList or try this :

use [your database name] go

SELECT * FROM match_team INNER JOIN match ON match_team.match_id = match.id

Secondary To avoid Conflicting tables use aliases ... see below for e.g. :

use [your database name] go SELECT * FROM match_team A INNER JOIN match B ON A.match_id = B.id

or start addressing with schema like : dbo.match_team.match_id = dbo.match.id

Upvotes: 0

jsampas
jsampas

Reputation: 11

SELECT * 
FROM match_team a
INNER JOIN [match] b ON a.match_id = b.id

Upvotes: 0

sagi
sagi

Reputation: 40481

The problem is that match is a reserved word in your RDBMS, you didn't specify your RDBMS, and it really depend on it, but try one of this:

SELECT * FROM match_team INNER JOIN `match` ON match_team.match_id = `match`.id
SELECT * FROM match_team INNER JOIN "match" ON match_team.match_id = "match".id

I don't know of any SQL language that uses another character for reserved words

Upvotes: 0

Satish Kumar sonker
Satish Kumar sonker

Reputation: 1288

best way to avoid conflict use table with database name. assuming your database is "Master"

SELECT * FROM Master.match_team INNER JOIN Master.match ON Master.match_team.match_id = Master.match.id

Upvotes: 0

FallAndLearn
FallAndLearn

Reputation: 4135

You can use double quotes for avoiding keywords.

SELECT * FROM match_team INNER JOIN "match" ON match_team.match_id = "match".id

Upvotes: 1

Related Questions