What means this query?
@numberx = @numberx -1
UPDATE th
SET @numberX= numberY= @numberX + 1
FROM Table1 th
INNER JOIN Table2 td ON th.Id = td.idth
WHERE td.anything = @anything
At line 3, what is this "double equality"? And what is this "from" and "inner" on an UPDATE?
The EXPLAIN keyword is used throughout various SQL databases and provides information about how your SQL database executes a query. In MySQL, EXPLAIN can be used in front of a query beginning with SELECT , INSERT , DELETE , REPLACE , and UPDATE .
The @CustID means it's a parameter that you will supply a value for later in your code. This is the best way of protecting against SQL injection. Create your query using parameters, rather than concatenating strings and variables.
A query can either be a request for data results from your database or for action on the data, or for both. A query can give you an answer to a simple question, perform calculations, combine data from different tables, add, change, or delete data from a database.
It's a multiple table update for assigning consecutive numbers to each row in Table1
where the corresponding row in Table2
has a specific value for the column anything
.
For each matching row it sets the column numberY
to the value of @numberX + 1
. It also reassigns that value back to @numberX
, which causes @numberX
to be incremented for each row.
This is known as a "quirky update". It is an undocumented and not guaranteed approach to generate running totals. In 2012 SUM() OVER (ORDER BY ...)
should be used instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With