Home > Mobile >  select and update value inside same table using where
select and update value inside same table using where

Time:04-24

I want to update the column values on the basis of the field. Means update attribute_id(46) against entity_id (maybe 13, or something else ) because i have different entity_ids for different entities.attribute_id(46) will get data from attribute_id(132) .What will be the query for this process?. for details please see the screenshot

enter image description here

CodePudding user response:

Update same table field from table table with where conditions using this type of query. (Sorry, this query is not tested in sql)

UPDATE t2
SET attribute_id = (select attribute_id from xxtable  t2 where attribute_id = 132)
FROM xxtable t2
where attribute_id = 46

CodePudding user response:

you can use a query like this:

UPDATE `tablename` a 
    INNER JOIN `tablename` b
    ON b.attribute_id = 132 AND b.entity_id = b.entity_id
    SET a.value = b.value  
    WHERE  a.attribute_id = 46 AND a.entity_id = 13 ;
  • Related