Re: Need help updating a whole column in one table from another table

From: Date: Tue, 14 Apr 2009 23:35:17 +0000
Subject: Re: Need help updating a whole column in one table from another table
References: 1 2 3 4  Groups: php.windows 
Request: Send a blank email to php-windows+get-29265@lists.php.net to get a copy of this message
The following SQL query UPDATE species2 AS s LEFT JOIN sci_genera AS sg ON (sg.genus_name = LEFT(s.species_name, LOCATE(' ', s.species_name) - 1)) SET s.generalID = sg.generalID; alters the contents of species2 to become ID species_name 1 Quercus rubra 2 Dalbergia nigra Assuming I understood your intent correctly, this should be the result you are after. This should fix your table. It does what you are trying with PHP, but using SQL only. With indices on the relevant fields it will probably be (much) faster too.
Our messages got long enough (along with the abstraction of supper ;-) ) that I forgot to mention that I tried to run it in a SQL query window in phpmyadmin. I got the following error instead:
        #1054 - Unknown column 's.generalID' in 'field list'
It must need some minor tweeking yet. This script is at an SQL level past my own understanding so far. If we get it to work yet, it should be quite the instructive lesson for me. I still stand to gain hours of otherwise hand correcting when it finally works. With thanks to this point, Bill Mudry (Mississauga, ON Canada)
-- Niel Archer niel.archer (at) blueyonder.co.uk -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.windows (#29265) next »