I'm attempting to resolve an issue with another devs mysql statement and I cannot find any clear answer in the various online docs I'm reading.
I'm hoping one or more of you SQL guru's might be able to enlighten me?
Let say tableA has an auto_increment key and our task is to retrieve a record from tableA based on a supplied key value and then insert it into the same table using an auto-assigned new key. During the transition certain fields moving tableA to the new record must be changed/nulled so the majority of the data is the same except that the access key is new and certain fields are nulled/changed.
Currently the program has something like this:
INSERT INTO tableA SET SELECT * from tableA WHERE tableA.key = 'whatever'
First, is this anywhere near correct in its format and intent?
Second, if it is then is there a way to change/null those certain fields during the move?
or must one then perform an UPDATE SET based on the new/retrieved key?
I hope I'm explaining this sufficiently clear to make sense.
I usually keep my SQL queries simpler to avoid things like this. But if there's a way it makes for good learning as well.
Thanks in advance.
I'm hoping one or more of you SQL guru's might be able to enlighten me?
Let say tableA has an auto_increment key and our task is to retrieve a record from tableA based on a supplied key value and then insert it into the same table using an auto-assigned new key. During the transition certain fields moving tableA to the new record must be changed/nulled so the majority of the data is the same except that the access key is new and certain fields are nulled/changed.
Currently the program has something like this:
INSERT INTO tableA SET SELECT * from tableA WHERE tableA.key = 'whatever'
First, is this anywhere near correct in its format and intent?
Second, if it is then is there a way to change/null those certain fields during the move?
or must one then perform an UPDATE SET based on the new/retrieved key?
I hope I'm explaining this sufficiently clear to make sense.
I usually keep my SQL queries simpler to avoid things like this. But if there's a way it makes for good learning as well.
Thanks in advance.