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
  • 704,970
  • 168
  • 1,303
  • 1,425
Arihant
  • 3,547
  • 14
  • 48
  • 79

2 Answers2

0

You can obtain it by the related select

 select id from  relations  WHERE element_from='abc'
ScaisEdge
  • 129,293
  • 10
  • 87
  • 97
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
  • 73,987
  • 13
  • 62
  • 116