Neeraj Dangol
Neeraj Dangol

Reputation: 223

Sorting the database result after search

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

Answers (3)

Janaki
Janaki

Reputation: 195

select * from table where Name like '%jerry%' order by Name desc

Upvotes: 0

Matt Healy
Matt Healy

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

Vodun
Vodun

Reputation: 1385

try

 $sql = "select * from table where Name like %jerry% order by Name";

Upvotes: 0

Related Questions