davepmiller
davepmiller

Reputation: 2708

MySql - Trouble Creating View

Receiving this message when trying to create a view in MySql. I've tried giving an alias to each column as well and still receive an error. Wha Happon!? Thanks in advance.

Error Message

ERROR 1060: Duplicate column name 'ID'

Code

CREATE VIEW contactnotes AS
SELECT contact.ID, log.ID, contact.Name, log.notes
FROM log 
JOIN contact 
ON log.ID = contact.ID

Alias Attempt

CREATE VIEW contactnotes AS
SELECT contact.ID as id1, log.ID as id2, contact.Name, log.notes
FROM log 
JOIN contact 
ON id1 = id2

Upvotes: 1

Views: 80

Answers (1)

Michael Benjamin
Michael Benjamin

Reputation: 2915

CREATE VIEW contactnotes AS
SELECT contact.ID as id1, log.ID as id2, contact.Name, log.notes
FROM log 
JOIN contact 
ON log.ID = contact.ID

or

CREATE VIEW contactnotes AS
SELECT contact.ID as id1, log.ID as id2, contact.Name, log.notes
FROM log 
INNER JOIN contact USING (ID)

Upvotes: 4

Related Questions