SQL UPDATE STATEMENT NOT WORKING?

February 17, 2010 - 5:27 am

UPDATE TABLENAME as a
SET a.NAME = b.NAME2
FROM TABLENAME2 as b
WHERE
a.ID = b.ID2

What’s wrong, it is not working?

I don’t see anything wrong the the statement alone. What is it not doing? Are you getting errors? Just not updating? Is ID2 the correct field name in TABLENAME2? ID2 seems a little odd. So does NAME2.

If the two tables have different names (ID vs ID2, Name vs Name2) you don’t need the ‘as’ clauses. If they do have the same name, don’t put the 2 after it.

That’s all I can think of without more information.

Good luck.

2 Responses to “SQL UPDATE STATEMENT NOT WORKING?”

  1. Mantis Says:

    I don’t see anything wrong the the statement alone. What is it not doing? Are you getting errors? Just not updating? Is ID2 the correct field name in TABLENAME2? ID2 seems a little odd. So does NAME2.

    If the two tables have different names (ID vs ID2, Name vs Name2) you don’t need the ‘as’ clauses. If they do have the same name, don’t put the 2 after it.

    That’s all I can think of without more information.

    Good luck.
    References :

  2. TheMadProfessor Says:

    This is one of the main reasons you use a relational database to begin with…to minimize redundant data. What’s wrong is that your table structure is not normalized. If the two tables are related by ID, there is no reason to retain the name in both…that just results in you having to try and keep the names synched up.
    References :

Leave a Reply