Microsoft
Software
Hardware
Network
Question : Simple MySQL query to update a table with different values from same table
Hello,
I have a table (simplified) with the following rows
Code Value Year
1 NULL 2009
1 123 NULL
2 NULL 2009
2 234 NULL
3 NULL 2009
3 345 NULL
I want to update all the 2009 records for each code, with the equivalent value where year=NULL. There will never be more than one 2009 and one NULL record for each code, but there may not always be both for each code.
I think this ought to be a very simple query, but not quite sure how to figure it out. I am hoping someone can give me a failsafe solution- I have large tables and am on a shared host and don't want to run a query that gets stuck and affects the performance of other sites on the host.
Thanks very much!
Answer : Simple MySQL query to update a table with different values from same table
do you mean this? :
UPDATE table1 t1 JOIN table1 t2 ON t1.code= t2.code
SET t1.Value=t2.value
where t1.year=2009 and t2.year is null
Random Solutions
Multiple Monitors
ComboBox background color still leaves a white border
find out an (x,y) location of a point on a circle's edge C#
How to copy rows from a table and put them in same table and joined to two other tables ?
SQL Insert INTO script syntax error
Access 2003 - Upon opening DB, .dlls and .ocx errors
Code Pause - sometimes
Upgrading Windows Business Vista to Windows 7 on a Sony Vaio UX series micro computer due to low HDD space
Reason for MyProj.csproj.FileListAbso<wbr />lute.txt
HTTP Error 403.1 publishing WCF Service