Sql Order By?!

Discussion in 'PHP' started by jmansa, Oct 6, 2008.

  1. #1
    I'm trying to get records from db and I want to first order it by something and when that is established the the order it by something else...

    My db has following tables...

    id
    uid
    name
    aproved

    I want to first get all the records that has been aproved (the record for this is 1, if not aproved it has a 0). When that is established I want to show all the records for that user first alphabetic and then all the others in alphabetic order... Hope this is understandable...
     
    jmansa, Oct 6, 2008 IP
  2. Kuldeep1952

    Kuldeep1952 Active Member

    Messages:
    290
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    60
    #2
    What database are you using - Mysql or SQL Server?

    id, uid, name and approved are fields or columns, not tables.

    What is the name of the table?
     
    Kuldeep1952, Oct 6, 2008 IP
  3. jmansa

    jmansa Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    mysql, and the table is "test"...
     
    jmansa, Oct 6, 2008 IP
  4. Greg Carnegie

    Greg Carnegie Peon

    Messages:
    385
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    SELECT * FROM test WHERE approved = 1 ORDER BY name ASC
    
    Code (markup):
    I think you should read some mysql tutorials first as these are the most basic queries in mysql.
     
    Greg Carnegie, Oct 6, 2008 IP
  5. David Brent

    David Brent Peon

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hey, i entirely agree with greg. Sometimes humping in the deep end is the best way but not in this case!

    Most programs come with a built in tutorial. This will guide you through the basics and lay a good foundation as you progress and need to learn more. Trust me, i learned the hard way (a number of times!)
     
    David Brent, Oct 6, 2008 IP