0

I want to get the ID of the row on which an UPDATE function is being performed in the same SQL query.

Something like this:

Select id 
from relations 
where (UPDATE relations set x1 ='0', y1='0' WHERE element_from='abc')

I know this can be done by two separate queries but is there a way to get it in one single query?

Columns in table:

id_main     
id      
type        
x1      
y1      
x2      
y2      
element_from        
element_to      
d       
session     
name
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Arihant
  • 3,847
  • 16
  • 55
  • 86

2 Answers2

0

You can obtain it by the related select

 select id from  relations  WHERE element_from='abc'
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
0

You can try like below (Idea taken from How to get ID of the last updated row in MySQL?)

SET @update_id := 0;
UPDATE relations set x1 = '0', y1 = '0', id = (SELECT @update_id := id)
WHERE element_from = 'abc';
SELECT @update_id;
Community
  • 1
  • 1
Rahul
  • 76,197
  • 13
  • 71
  • 125