I would like to move a row to the bottom of the result set given a matched condition.
+-------+------------+
|Symbol | Percentage |
|-------|------------|
|VG | 20 |
|-------|------------|
|CASH | 20 |
|-------|------------|
|GOOG | 60 |
+-------+------------+
ex:
SELECT * FROM TableName -SEND TO END OF RESULT SET- WHERE symbol = 'CASH'
result set:
GOOG
VG
CASH
I need to write an exception for an ORDER BY
statement. To put the query into plain english - SELECT
an entire row, ordering by a timestamp, except if the symbol is "CASH"
You can move rows from one table to another with the help of INSERT INTO SELECT statement.
I thought of mixing a bit of SQL with my server-side language, eg. (moving up Frank): if (newPosition > oldPosition) { UPDATE people SET position = position - 1 WHERE listId = 1 AND position <= @newPosition AND Name != "Frank"; UPDATE people SET position = @newPos WHERE listId = 1 AND Name="Frank"; } else { … }
MySQL SELECT specific rows When a user wants to retrieve some individual rows from a table, a WHERE clause has to be added with the SELECT statement immediately followed by a condition. Here * indicates all columns.
To select the last row, we can use ORDER BY clause with desc (descending) property and Limit 1.
To change the order of the rows in a result set you should use ORDER BY:
SELECT *
FROM TableName
ORDER BY symbol = 'CASH', timestamp
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