1

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?

Frits Verstraten
  • 2,049
  • 7
  • 22
  • 41

5 Answers5

1

You can use double quotes for avoiding keywords.

SELECT * FROM match_team INNER JOIN "match" ON match_team.match_id = "match".id
FallAndLearn
  • 4,035
  • 1
  • 18
  • 24
0

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
Satish Kumar sonker
  • 1,250
  • 8
  • 15
0
SELECT * 
FROM match_team a
INNER JOIN [match] b ON a.match_id = b.id
jsampas
  • 11
  • 2
0

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

sagi
  • 40,026
  • 6
  • 59
  • 84
0

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