Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In a comment, you supplied this sample data (I've created field names):</p> <pre><code> CompanyName CompanyYear Amount Website Contact starbucks 2009 100$ starbucks.com matt bucky starbucks 2010 200$ null null </code></pre> <p>Since you've said the company names match, something like this:</p> <pre><code> UPDATE tblCompany INNER JOIN tblCompany AS C2 ON tblCompany.CompanyName = C2.CompanyName SET tblCompany.Website = C2.Website WHERE tblCompany.Website Is Null AND C2.Website Is Not Null AND tblCompany.CompanyYear=2010 AND C2.CompanyYear=2009; </code></pre> <p>This assumes that you want to update 2010 records with data from 2009 records, and that for each company there's only one record for each year.</p> <p>To update the contact name, you'd run the query again, suitably altering the SET statement and WHERE clause:</p> <pre><code> UPDATE tblCompany INNER JOIN tblCompany AS C2 ON tblCompany.CompanyName = C2.CompanyName SET tblCompany.Contact = C2.Contact WHERE tblCompany.Contact Is Null AND C2.Contact Is Not Null AND tblCompany.CompanyYear=2010 AND C2.CompanyYear=2009; </code></pre> <p>If there are older records that might have useful data, it's possible to write some complicated SQL with subqueries that would do it all in one go, but I'd just do it with multiple runs of the same SQL, first comparing 2010 to 2009, then to 2008, then to 2007, etc. Eventually, there won't be any more Null records.</p> <p>(this also seems more like a StackOverflow question than a ServerFault one, but what do I know? I can never figure out what belongs where)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload