I have a database table like this
<table>
<tr>
<th>no</th>
<th>name</th>
<th>income</th>
<th>work</th>
<th>score</th>
</tr>
<tr>
<td>1</td>
<td>alan</td>
<td>US 100</td>
<td>Designer</td>
<td>30%</td>
</tr>
<tr>
<td>2</td>
<td>lara</td>
<td>US 100</td>
<td>Doctor</td>
<td>34%</td>
</tr>
<tr>
<td>3</td>
<td>foong</td>
<td>US 100</td>
<td>Teacher</td>
<td>7%</td>
</tr>
<tr>
<td>4</td>
<td>Rose</td>
<td>US 50</td>
<td>Waitress</td>
<td>55%</td>
</tr>
<tr>
<td>5</td>
<td>Jack</td>
<td>US 30</td>
<td>Programmer</td>
<td>50%</td>
</tr>
<tr>
<td>6</td>
<td>jeff</td>
<td>US 3</td>
<td>Lawyer</td>
<td>90%</td>
</tr>
<tr>
<td>7</td>
<td>elson</td>
<td>US 2000</td>
<td>Footballer</td>
<td>60%</td>
</tr>
<tr>
<td>8</td>
<td>steve</td>
<td>US 22</td>
<td>chef</td>
<td>10%</td>
</tr>
<tr>
<td>9</td>
<td>albert</td>
<td>US 35</td>
<td>Admin</td>
<td>80%</td>
</tr>
<tr>
<td>10</td>
<td>warnock</td>
<td>US 5</td>
<td>Technicer</td>
<td>1%</td>
</tr>
<table>
then I want show the result on the table is Top 5 Score only
but my table is sort by income column.
I use this string to query:
SELECT * FROM table ORDER by score DESC, income ASC LIMIT 0,5
but my result is sort by score not income.
I want the table is sort by income with top 5 score only
any idea on this?
thanks for advance.
Just treat your initial result set as a sub-query of one in which you sort your final results by income: