Recently I wrote about the myth that you can't use an alias in an UPDATE statement. You can of course, and the trick is to make sure that the alias is used in the FROM clause of the statement.
Aliases are often used to name a column that is the result of an arithmetic expression or summary function. An alias is one word only. If you need a longer column name, then use the LABEL= column-modifier, as described in column-modifier.
If you run a DELETE statement with no conditions in the WHERE clause, all of the records from the table will be deleted.
Example - Using TOP keyword Let's look at a SQL Server example, where we use the TOP keyword in the DELETE statement. For example: DELETE TOP(10) FROM employees WHERE last_name = 'Anderson'; This SQL Server DELETE TOP example would delete the first 10 records from the employees table where the last_name is 'Anderson'.
To alias the table you'd have to say:
DELETE f FROM dbo.foods AS f WHERE f.name IN (...);
I fail to see the point of aliasing for this specific DELETE
statement, especially since (at least IIRC) this no longer conforms to strict ANSI. But yes, as comments suggest, it may be necessary for other query forms (eg correlation).
The delete statement has strange syntax. It goes like this:
DELETE f FROM foods f WHERE (f.name IN ('chickens', 'rabbits'))
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