voodoochicken Posted March 5, 2008 Share Posted March 5, 2008 hi, i have a table with a field 'other_entry' (let's suppose), which is another entry in the same table, for example:integer key, integer key_of_related_entry, integer other_field, enum('value1', 'value2', etc) criteriakey is the unique integer key to the entry, and key_of_related_entry is the key to another entryi want to do something likeupdate 'table'set other_field = (key_of_related_entry -> other_field)+1where criteria=valuexhow do i handle the 'pointer-like' reference, where the value in 'other_field' depends on the value of this same field, but in some other entry of the same table? tnx Link to comment Share on other sites More sharing options...
justsomeguy Posted March 5, 2008 Share Posted March 5, 2008 I can't find notes in the MySQL manual on what types of expressions you can use for the value of a column, but this might work:UPDATE table AS a SET other_field = (SELECT other_field FROM table AS b WHERE b.key = a.other_key) + 1 WHERE ... Link to comment Share on other sites More sharing options...
voodoochicken Posted March 5, 2008 Author Share Posted March 5, 2008 UPDATE table AS a SET other_field = (SELECT other_field FROM table AS b WHERE b.key = a.other_key) + 1 WHERE ...you mean i can place a 'select' as a valid value in an asignment different than a 'in'?if that works, thats what i was needing! Link to comment Share on other sites More sharing options...
justsomeguy Posted March 6, 2008 Share Posted March 6, 2008 I'm not sure if you can or not, that's what I was looking for without success in the documentation. Link to comment Share on other sites More sharing options...
voodoochicken Posted March 6, 2008 Author Share Posted March 6, 2008 how can you solve this using a temp -where you store the result select- table in a single command (to pass to php)? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 6, 2008 Share Posted March 6, 2008 If you want to use a temp table then you'll need to write a stored procedure. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.