codrgii Posted March 3, 2010 Share Posted March 3, 2010 i'm trying to update a column of a table by selecting two different values from 2 different tables, i'm doing - UPDATE table_temp SET sum = table_temp.Point - table_RATING.Point and when trying that it pops up an error saying The multi-part identifier "table_RATING.Point" could not be bound. does anyone know what i'm doing wrong? Link to comment https://forums.phpfreaks.com/topic/193989-updating-tables/ Share on other sites More sharing options...
Wolphie Posted March 3, 2010 Share Posted March 3, 2010 You could try UPDATE table_temp SET sum = table_temp.Point - (SELECT Point FROM table_RATING) Link to comment https://forums.phpfreaks.com/topic/193989-updating-tables/#findComment-1020868 Share on other sites More sharing options...
aeroswat Posted March 3, 2010 Share Posted March 3, 2010 You could try UPDATE table_temp SET sum = table_temp.Point - (SELECT Point FROM table_RATING) ...? I could be wrong but I think this is nowhere near correct syntax to produce any results. I'm not sure if its possible to do this without having some kind of link between the two tables. In that case you would need to JOIN the tables together on some kind of key. Then you would be able to access each corresponding record. Of course I'm fairly new so this could be wrong too Link to comment https://forums.phpfreaks.com/topic/193989-updating-tables/#findComment-1020875 Share on other sites More sharing options...
codrgii Posted March 3, 2010 Author Share Posted March 3, 2010 This errors UPDATE table_temp SET sum = table_temp.Point - (SELECT Point FROM table_RATING) Link to comment https://forums.phpfreaks.com/topic/193989-updating-tables/#findComment-1020877 Share on other sites More sharing options...
aeroswat Posted March 3, 2010 Share Posted March 3, 2010 This errors UPDATE table_temp SET sum = table_temp.Point - (SELECT Point FROM table_RATING) Look into the JOIN keyword like I told you. That syntax is incorrect... Link to comment https://forums.phpfreaks.com/topic/193989-updating-tables/#findComment-1020879 Share on other sites More sharing options...
codrgii Posted March 3, 2010 Author Share Posted March 3, 2010 Look into the JOIN keyword like I told you. What kind of answer is that? have a read at what i asked in my post first on this topic... does anyone know what i'm doing wrong? this is what i asked, i'm fairly new to php myself so any examples would be a real help. Link to comment https://forums.phpfreaks.com/topic/193989-updating-tables/#findComment-1020908 Share on other sites More sharing options...
aeroswat Posted March 3, 2010 Share Posted March 3, 2010 Look into the JOIN keyword like I told you. What kind of answer is that? have a read at what i asked in my post first on this topic... does anyone know what i'm doing wrong? this is what i asked, i'm fairly new to php myself so any examples would be a real help. This is the answer I gave you and the post I was referring to when I said "like I told you" You could try UPDATE table_temp SET sum = table_temp.Point - (SELECT Point FROM table_RATING) ...? I could be wrong but I think this is nowhere near correct syntax to produce any results. I'm not sure if its possible to do this without having some kind of link between the two tables. In that case you would need to JOIN the tables together on some kind of key. Then you would be able to access each corresponding record. Of course I'm fairly new so this could be wrong too I think you need a RTFM. The JOIN keyword is used to group two tables together. You need some kind of key to group them buy. Without knowing the way that anything is set up on your database we cannot do the work for you. Have you typed JOIN MySql into google? Link to comment https://forums.phpfreaks.com/topic/193989-updating-tables/#findComment-1020915 Share on other sites More sharing options...
MatthewJ Posted March 3, 2010 Share Posted March 3, 2010 Maybe something like UPDATE FROM table_RATING AS tr LEFT JOIN table_temp as tt ON yourprimarykey = yourforeignkey SET tt.point = tt.point - tr.point Link to comment https://forums.phpfreaks.com/topic/193989-updating-tables/#findComment-1020921 Share on other sites More sharing options...
codrgii Posted March 3, 2010 Author Share Posted March 3, 2010 UPDATE FROM table_RATING AS tr LEFT JOIN table_temp as tt ON POINT1 = POINT2 SET tt.point = tt.point - tr.point The syntax is wrong, Incorrect syntax near the keyword 'FROM' Link to comment https://forums.phpfreaks.com/topic/193989-updating-tables/#findComment-1020926 Share on other sites More sharing options...
MatthewJ Posted March 3, 2010 Share Posted March 3, 2010 Yeah, to my defense... it was early UPDATE table_temp, table_rating SET table_temp.`Point` = (table_temp.`Point` - table_rating.`Point`) WHERE table_temp.primarykey = table_rating.foreignkey Link to comment https://forums.phpfreaks.com/topic/193989-updating-tables/#findComment-1020986 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.