0

This is the query for SQL statement

UPDATE TrendingEvents
    SET Name = ?, Image = ?, Date = ?, EventCategory = ?
    WHERE ID = ?;')

I would like to access the ID of the other table within my TrendingEvents table. This is the example I've done although it doesn't fully work;

UPDATE TrendingEvents INNER JOIN
       Events AS eID
       ON TrendingEvents.ID = Events.ID
 SET Name = ?, Image = ?, Date = ?, EventCategory = ?
 WHERE eID = ?;')

I would like to update the TrendingEvents table with the ID column from Events table.

The error I'm getting from my statement is

Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'Name' 

Which just shows that I've poorly designed my query.

2 Answers 2

1

Both tables seem to contain a column called Name. You need to properly prefix the fields with the table name, like :

UPDATE 
    TrendingEvents AS t
    INNER JOIN Events AS e
        ON t.ID = e.ID 
    SET 
        t.Name = ?, 
        t.Image = ?, 
        t.Date = ?, 
        t.EventCategory = ? 
    WHERE e.eID = ?
Sign up to request clarification or add additional context in comments.

Comments

0

You have misused the table alias, so your query should not even compile. Try this:

UPDATE TrendingEvents te INNER JOIN
       Events e
       ON te.ID = e.ID
 SET te.Name = ?,
     te.Image = ?,
     te.Date = ?,
     te.EventCategory = ?
 WHERE e.eID = ?;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.