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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Bill Mudry wrote:


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)





Bill,

I was reading over this thread this morning and I think it would be helpful to everyone watching it if you could post the structure of your db. You mentioned phpMyAdmin. From there simply run the 'DESCRIBE sci_genera;'. Go to the print view for the results and you can copy and paste it into an email. Do the same for the species table.

Cheers,
James

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux