Hi i have 100 records in my SQL table i want to sort them ASC by name but i need one record on top of all record nr 43.
Is there way i can pull this record 43 first and then everything else ASC order by name?
Trick is to do it in one query.
The SELECT TOP statement in SQL shows the limited number of records or rows from the database table. The TOP clause in the statement specifies how many rows are returned. It shows the top N number of rows from the tables in the output.
Note − All the databases do not support the TOP clause. For example MySQL supports the LIMIT clause to fetch limited number of records while Oracle uses the ROWNUM command to fetch a limited number of records.
To select first 10 elements from a database using SQL ORDER BY clause with LIMIT 10. Insert some records in the table using insert command. Display all records from the table using select statement. Here is the alternate query to select first 10 elements.
The SQL TOP clause is used to limit the number of rows returned. Its basic syntax is: SELECT TOP number | percent column_list FROM table_name ; Here, column_list is a comma separated list of column or field names of a database table (e.g. name, age, country, etc.)
No UNIONs or CASEs needed:
ORDER BY id = 43 DESC, name ASC
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