search

Home  >  Q&A  >  body text

Experiment with sorting after query limit

<p>So this is my first question here, please forgive me if something is wrong. </p> <p>I am trying to make a sort query based on constraints. </p> <p>So there is a Customers table with 90 records. </p> <p>I want to first perform a query limited to 3 records, and then sort the query results by a column called ContactName. </p> <p>I think this might be a nested query. Nested queries run fine in SQL Server, but don't know how to implement it in MySQL. </p> <p>Limit query:</p> <pre class="brush:php;toolbar:false;">Select * from customers limit 3;</pre> <p> Sort after limiting the query (my guess, but this doesn't work): </p> <pre class="brush:php;toolbar:false;">Select * from (Select * from customers limit 3) Order by ContactName;</pre> <p>Please help. Thanks. </p>
P粉237125700P粉237125700443 days ago682

reply all(1)I'll reply

  • P粉081360775

    P粉0813607752023-09-06 10:57:25

    You only need this

    Select * from customers Order by ContactName limit 3;

    reply
    0
  • Cancelreply