Raman Sinclair
Raman Sinclair

Reputation: 1283

SQL server ERROR Ambiguous column name

Can't understand what's wrong in this SQL query:

USE [My_db]
GO

SELECT ItemId
      ,Subject
      ,CreatedOn
  FROM ItemBase AS e
      INNER JOIN ItemExtensionBase AS p
      ON e.ItemId = p.ItemId
GO

Error:

 Msg 209, Level 16, State 1, Line 4
 Ambiguous column name 'ItemId'.

ItemId column exist in both tables.

Upvotes: 3

Views: 4467

Answers (2)

Szabolcs Dombi
Szabolcs Dombi

Reputation: 5783

Use e.ItemId or p.ItemId:

USE [My_db]
GO

SELECT e.ItemId
      ,Subject
      ,CreatedOn
  FROM ItemBase AS e
      INNER JOIN ItemExtensionBase AS p
      ON e.ItemId = p.ItemId
GO

Upvotes: 3

JDro04
JDro04

Reputation: 670

USE [My_db]
GO

SELECT e.ItemId
      ,Subject
      ,CreatedOn
  FROM ItemBase AS e
      INNER JOIN ItemExtensionBase AS p
      ON e.ItemId = p.ItemId
GO

You need to tell it which table to take the itemid field from

Upvotes: 5

Related Questions