vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I need help for update a table in this db: tab1: id F1 1 45 2 52 3 10 4 25 .... tab2: id RIFTAB1 F1_2 1 3 45 2 4 12 3 4 10 4 1 40 5 2 80 .... I want to update every F1 in tab1 with min value of F1_2 where tab2.RIFTAB1=tab1.id : tab1: id F1 1 40 2 80 3 45 4 10 I tried this: UPDATE TAB1 SET F1= (SELECT MIN(F1_2) FROM TAB2 WHERE ???? Thank you in advance. bye, max |
| |||
| == Quote from Massimo (TOGLIMImassimo@pafin.it)'s article > I need help for update a table in this db: > tab1: > id F1 > 1 45 > 2 52 > 3 10 > 4 25 > ... > tab2: > id RIFTAB1 F1_2 > 1 3 45 > 2 4 12 > 3 4 10 > 4 1 40 > 5 2 80 > ... > I want to update every F1 in tab1 with min value of F1_2 where > tab2.RIFTAB1=tab1.id : > tab1: > id F1 > 1 40 > 2 80 > 3 45 > 4 10 > I tried this: > UPDATE TAB1 SET F1= (SELECT MIN(F1_2) FROM TAB2 WHERE ???? > Thank you in advance. > bye, > max what version of mysql are you running? if you are on 5.x you can write a stored procedure to do this very easily! -- POST BY: lark with PHP News Reader |
| |||
| "lark" <hamzee@sbcglobal.net> ha scritto nel messaggio news:8szci.63$Rw1.17@newssvr25.news.prodigy.net... > what version of mysql are you running? if you are on 5.x you can write a stored > procedure to do this very easily! > -- > POST BY: lark with PHP News Reader I have v 5. I already think that it need a stored procedure, I wished to know if it was possible to do it without SP. So, it seems it's not possible. thanx a lot by, max |
| |||
| On Fri, 15 Jun 2007 11:56:12 +0200, "Massimo" wrote: >[...] >I want to update every F1 in tab1 with min value of F1_2 where >tab2.RIFTAB1=tab1.id : >[...] update tab1 set tab1.F1 = ( select min(tab2.F1_2) from tab2 where tab2.RIFTAB1 = tab1.id ) -- Ross McKay, Toronto, NSW Australia "Let the laddie play wi the knife - he'll learn" - The Wee Book of Calvin |
| ||||
| "Ross McKay" <rosko@zeta.NOT.THIS.BIT.org.au> ha scritto nel messaggio news:ur5d73ls4o8pehovalk01vi7hjl32imh10@4ax.com... > update tab1 set tab1.F1 = ( > select min(tab2.F1_2) from tab2 where tab2.RIFTAB1 = tab1.id > ) It works! thank you bye, max |