SQL Sort Command

I am looking for an SQL command that will sort the ID column in my database in ascending order.

**EDIT **

oops the correct response is on the post below.

Matt


ORDER BY ID ASC

I tried both and either of them worked. Do I have to put the table name in some where?

Yes, the ORDER BY clause comes after everything in the SQL statement.


SELECT
  ID
FROM
  table_name
WHERE
  <conditions>
ORDER BY
  ID ASC

The entire SQL command is"

Select Field Names From Table Name ORDER BY [/I]ID Field Name[I] ASC.

or
Select * From Customers Order By CustomerID ASC

or Select CustomerID, CustFirstName, CustLastName From Customers Order By CustomerID ASC

try those,

Matt

PS. Do you have to have the ASC? or is it default?

Yes ASC (ascending) is the default, but I put it there so that there’s no doubt about it next time when I read the SQL (I always can’t remember which is the default).

What do I put for the conditions? I just want it to sort the whole table.

If you have no conditions, just leave it out.

SELECT
  ID
FROM
  table_name
ORDER BY
  ID ASC

I tried that. I changed the code to:


SELECT
  *
FROM
  home
ORDER BY
  ID ASC

It does sort things, but only on the SQL query/queries page in phpmyadmin. When I got to the browse tab in phpmyadmin, nothing is changed.

I think you are mistaken in your understanding of databases. The records in a table are not sorted in any determinable way. So you can’t say that this record is record 1, that one is record 2 in the table.

When you view the records in, say, phpmyadmin, there is no specific ordering given to the records. If you want to view the records in a specific order, use the ORDER BY clause in an SQL statement. However, you can’t change the innate order because there is none.

Okay, I get it now. Thanks for all your help!