Reputation: 223
My database table is as follows:
Id Name
1 Jerry
2 Tom and Jerry
3 Jerrymouse
4 Tom
My sql seach statement is as follows:
$sql = "select * from table where Name like %jerry%";
When i run the query, the result is as follows the result will be obtained in the same order as above(except Tom). But the result i want is as follows:
Jerry
Jerrymouse
Tom and Jerry
Can anyone help me to display the result in a sorted form as above using sql?
Upvotes: 0
Views: 105
Reputation: 18531
Refer to the documentation for sorting rows. In this case, you can try:
select * from table where Name like '%jerry%' order by Name;
Upvotes: 1
Reputation: 1385
try
$sql = "select * from table where Name like %jerry% order by Name";
Upvotes: 0