MySQL: order by primary key

lazyweb help… why can’t I do this?

SELECT * from table order by primary desc

man, that would be cool. Not having to know the primary key’s name seems like something I should be able to roll with in a MySQL statement. Maybe I’m getting the syntax wrong. I’ll never know because for as good as http://www.php.net is at documentation of the api, the polar opposite is true for http://dev.mysql.com There’s just not the same participation by a developer base that php’s site has. The examples are inadequate and not very helpful. I’d love to contribute or ask questions, but… it just doesn’t seem like they put up user contributed content like php does.

Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter
Bookmark and Share

  • Tozzano

    Hi,

    What I cannot believe is that no one has commented on this :)

    Google returned this page as a result of my query ‘mysql order by primary’ There must be a way to use that logic (not having to provide the primary index name in the order by clause. Anyway…

    I just started looking – but I thought I would say hi and say that I agree that the PHP knowledge base is better than the mySQL documentation and dev chat base.

  • Tozzano

    Hi,

    What I cannot believe is that no one has commented on this :)

    Google returned this page as a result of my query ‘mysql order by primary’ There must be a way to use that logic (not having to provide the primary index name in the order by clause. Anyway…

    I just started looking – but I thought I would say hi and say that I agree that the PHP knowledge base is better than the mySQL documentation and dev chat base.

  • Jason

    The command should work:

    SELECT * from table order by id;

  • Jason

    The command should work:

    SELECT * from table order by id;

  • 12centuries

    Assuming that your primary key is the first field in the table, this will work:

    SELECT * FROM `table` ORDER BY 1

    Cheers!