darga333 Posted May 28, 2006 Share Posted May 28, 2006 Hi I am trying to set t1.sImagePath=t2.sImagePath and it is not working for some reasonThis code selects what I need[code]SELECT t1.sImagePath,t2.sImagePath FROM members t1, discount t2 WHERE t1.bBusiness = 1 AND t1.user_id = t2.iMemberId AND t2.sActive = 1 GROUP BY t1.user_id[/code]does anyone know how to do that? Link to comment https://forums.phpfreaks.com/topic/10631-setting-one-column-equal-to-another-column-when-using-two-tables/ Share on other sites More sharing options...
Barand Posted May 28, 2006 Share Posted May 28, 2006 [quote]Starting with MySQL Version 4.0.4, you can also perform UPDATE operations that cover multiple tables: UPDATE items,month SET items.price=month.priceWHERE items.id=month.id;The example shows an inner join using the comma operator, but multiple-table UPDATE statements can use any type of join allowed in SELECT statements, such as LEFT JOIN. Note: you cannot use ORDER BY or LIMIT with multiple-table UPDATE. [/quote] Link to comment https://forums.phpfreaks.com/topic/10631-setting-one-column-equal-to-another-column-when-using-two-tables/#findComment-39663 Share on other sites More sharing options...
darga333 Posted May 28, 2006 Author Share Posted May 28, 2006 Hey for some reason it is giving me the following error:#1064 - You have an error in your SQL syntax near 'discount SET members.sImagePath = 'discount.sImagePath' WHERE memb' at line 1 UPDATE members,discount SET members.sImagePath='discount.sImagePath' WHERE members.user_id = discount.iMemberIddoes anyone know what i am doing wrong? Link to comment https://forums.phpfreaks.com/topic/10631-setting-one-column-equal-to-another-column-when-using-two-tables/#findComment-39775 Share on other sites More sharing options...
Barand Posted May 28, 2006 Share Posted May 28, 2006 Remove single quotes round 'discount.sImagePath' Link to comment https://forums.phpfreaks.com/topic/10631-setting-one-column-equal-to-another-column-when-using-two-tables/#findComment-39776 Share on other sites More sharing options...
darga333 Posted May 28, 2006 Author Share Posted May 28, 2006 it still gives me the same errorI dont understand what I could be doing wrong I have it set up exactly how you are sayingUPDATE members,discount SET members.sImagePath=discount.sImagePath WHERE members.user_id = discount.iMemberIdi am trying to set members.sImagePath = discount.sImagePath ... could it possibly be because I set members.sImagePath as null when i created the column? Link to comment https://forums.phpfreaks.com/topic/10631-setting-one-column-equal-to-another-column-when-using-two-tables/#findComment-39780 Share on other sites More sharing options...
Barand Posted May 29, 2006 Share Posted May 29, 2006 What version of MySql are you using? Link to comment https://forums.phpfreaks.com/topic/10631-setting-one-column-equal-to-another-column-when-using-two-tables/#findComment-39808 Share on other sites More sharing options...
darga333 Posted May 29, 2006 Author Share Posted May 29, 2006 This is what the screen says:Welcome to phpMyAdmin 2.5.6MySQL 3.23.56 Link to comment https://forums.phpfreaks.com/topic/10631-setting-one-column-equal-to-another-column-when-using-two-tables/#findComment-39840 Share on other sites More sharing options...
Barand Posted May 29, 2006 Share Posted May 29, 2006 Now read my first post on this topic carefully Link to comment https://forums.phpfreaks.com/topic/10631-setting-one-column-equal-to-another-column-when-using-two-tables/#findComment-39898 Share on other sites More sharing options...
darga333 Posted June 1, 2006 Author Share Posted June 1, 2006 Hey Barand, do you know of a way with the older version of mysql? I am going to upgrade mysql but at a later date.I did several searches online and tried to come up with a solution before replying back to this topic. I have another question also. It said that i was tryign to do was a multiple table update when infact I am just updating 1 table. Maybe you might know why that is? Link to comment https://forums.phpfreaks.com/topic/10631-setting-one-column-equal-to-another-column-when-using-two-tables/#findComment-40782 Share on other sites More sharing options...
Barand Posted June 1, 2006 Share Posted June 1, 2006 UPDATE members,discount Two table name therefore multiple.You would have to do it with PHP - loop through the discount records and update each matching member record. Link to comment https://forums.phpfreaks.com/topic/10631-setting-one-column-equal-to-another-column-when-using-two-tables/#findComment-40805 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.