views:

114

answers:

3

Let's say that I have the following code:

SELECT * FROM table where company LIKE '%Auto%'

And I receive more results, and I want to have an option to sort the results alphabetically, let's say that the user wants to sort the search results for the ones which start with "C"!

Best Regards,

+2  A: 

Use the ORDER BY clause:

SELECT *
FROM table
where company LIKE '%Auto%'
order by company
wallyk
+1  A: 

add ORDER BY company, assuming you want to sort by the company value.

Ned Batchelder
+5  A: 

Well, it seems that you are talking about two different things. If you are interested in sorting you would need to use the ORDER BY clause:

SELECT * FROM table ORDER BY name

If you want to filter the results by items that start with the letter 'C' then you would want to add another LIKE clause with that letter:

SELECT * FROM table where company LIKE '%Auto%' AND name LIKE 'C%'

Additionally you'll notice that the name filter only has the % after the query. This is the syntax for "starts with"

bendewey