4
I would like to perform an update ordering the results of the same, for this I wanted to run an update like this:
UPDATE pessoa SET nome = 'Jose'
WHERE sobrenome LIKE '%Betalla%'
ORDER BY nome
But when I try to perform this update there is an incorrect syntax error near "ORDER".
I would like to order by to get the first result of the ordered query.
But the
UPDATE
does not return anything, as hell you want to use theORDER BY
? the.0– DH.
One of the reasons is update does not return records, it can even return the number of affected lines which is something totally different ;)
– rray
You can select with this query after the update or generate N updates with a select so you can get the id of all lines that will be changed.
– rray
I wanted to order the order in which the update will be carried out, would have how to accomplish this?
– William
Update will not return records. What could be is an [tag:Insert] with [tag:select] already sorted.
– Eduardo Mendes
@William Why? It makes no sense that you need to order how the command will happen. In the end the result is the same.
– DH.
@Eduardomendes in the case I think I need an update, so an update with select already sorted would solve?
– William
I think the closest would be, like,
SELECT +'UPDATE .... WHERE sobrenome like \'%abc\'+ id FROM tabela ORDER BY algo
– rray
@DH. has a case here that this ordering would alter the final result, so.
– William
@William Only situation that I can imagine this is trying to update a Primary Key being that the table points to itself, but there is a good reason to exist Constraint that prevents the value of a PK change
– DH.
@William, I saw a solution for update with select, take a look at this link and see if it helps you
– Eduardo Mendes