I'm having beginner troubles with MySQL. I'm trying to build a DB of parts which have a ten digit alphanumeric part number based on the department and class of a part. For example, a part from department "Foo" of class "Bar" might be FOBAR10000. The departments and classes are stored in their own tables, so I store the IDs with the part instead of the strings "FO" and "BAR" in the parts table.
I've come up with a MySQL query to lookup and concatenate the full part name.
SELECT pl.idPartsList as 'resultid', concat(pd.DeptShortName, pc.ClassShortName,pl.PartIntID) as 'Fullname'
FROM partdepartments pd, partclasses pc, partslist pl
WHERE pl.PartDeptId = pd.idPartDepartments and pl.PartClassID = pc.idPartClasses;
Which generates:
resultid | Fullname
---------------------
1 | FOBAR10000
I want to assign this result back to the part under the column PartFullAlphaID, as follows, to avoid having to run this query often.
Before:
idPartslist | PartDeptID | PartClassID | PartIntID | PartFullAlphaID
---------------------------------------------------------------------
1 | 1 | 1 | 10000 |
After:
idPartslist | PartDeptID | PartClassID | PartIntID | PartFullAlphaID
---------------------------------------------------------------------
1 | 1 | 1 | 10000 | FOBAR10000
but the following doesn't work:
UPDATE test_db_1.partslist
SET PartFullAlphaID = Fullname
WHERE test_db_1.partslist.idPartsList = resultid;
Because: Error Code: 1054. Unknown column 'resultid' in 'where clause'
How can I assign this string value back to the part?