In SELECT * FROM view_table The result always is
-----------------------
|| id || author ||
-----------------------
|| 1 || a || <--
|| 1 || c || <--
|| 1 || b || <--
|| 2 || d ||
|| 3 || e ||
But when SELECT * FROM view_table WHERE id=1 the result is
-----------------------
|| id || author ||
-----------------------
|| 1 || a ||
|| 1 || b ||
|| 1 || c ||
Or
-----------------------
|| id || author ||
-----------------------
|| 1 || b ||
|| 1 || c ||
|| 1 || a ||
Or
-----------------------
|| id || author ||
-----------------------
|| 1 || a ||
|| 1 || c ||
|| 1 || b ||
Or
..
I want to SELECT * FROM view_table WHERE id=1 and get the results in the same order as SELECT * FROM view_table. How to solve it
Thank You.
The order of results is never guaranteed unless you use an ORDER BY clause. How you want to order it, is up to you.
For example,
SELECT *
FROM view_table
WHERE id = 1
ORDER BY author
This will sort it based on the author's name (from A to Z, or Z to A if you use ORDER BY author DESC).
Alternatively you can add a Created column and then order by that column instead, which holds the timestamp when it was created. That could mimic an order that you want to keep.
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