My query
select * from product where productId in(25,36,40,1,50);
Result shows as follows
`productId ProductName Qty Price`
-------------------------------------
`1 | namesome | 5 | 25.00`
`25 | namesome | 5 | 35.00`
`36 | namesome | 5 | 35.00`
`40 | namesome | 5 | 35.00`
`50 | namesome | 5 | 35.00`
I did not use any order by
clause, But its automatically applied order by productId
,
I need result with out any sort, as follows
`productId ProductName Qty Price`
-------------------------------------
`25 | namesome | 5 | 25.00`
`36 | namesome | 5 | 35.00`
`40 | namesome | 5 | 35.00`
`1 | namesome | 5 | 35.00`
`50 | namesome | 5 | 35.00`
How can I achieve this?
Database Engine: MyIsam, Collation: utf8_general_ci, PrimaryKey on productId
In SQL Server if you don't specify an order then you may get either an index scan or an allocation ordered scan for example. Plus also you might encounter the "advanced scanning" / merry-go-round scanning feature.
Only some database systems support a SELECT statement which has no FROM clause (Microsoft SQL Server and MySQL do). If your database system requires a FROM clause, then all you need to do is select the strings from any convenient table where it is easy to target a specific row.
SQL queries initiated by using a SELECT statement support the ORDER BY clause. The result of the SELECT statement is sorted in an ascending or descending order.
The ORDER BY statement in SQL is used to sort the fetched data in either ascending or descending according to one or more columns. By default ORDER BY sorts the data in ascending order. We can use the keyword DESC to sort the data in descending order and the keyword ASC to sort in ascending order.
select *
from product
where productId in(25,36,40,1,50)
order by find_in_set(productId, '25,36,40,1,50');
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