SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ORDER BY being ignored :(

    I've got a very simple table:

    Code:
    CREATE TABLE `active_songs` (
      `id` int(11) NOT NULL auto_increment,
      `song_title` varchar(255) default NULL,
      `artist_name` varchar(255) default NULL,
      `label` varchar(255) default NULL,
      `hide_from_chart` varchar(255) default NULL,
      `created` datetime default NULL,
      `created_week` int(11) default NULL,
      `user_added` tinyint(4) default NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    And when I run a simple SELECT on it with an ORDER BY directive it doesn't order by the field I specify. It is only ordering by the ID field.

    Code:
    SELECT * FROM active_songs WHERE hide_from_chart != '1' ORDER BY 'song_title' ASC
    The query above should output the song list and order them by song title (obviously) but it's outputting them by ID no matter what. No errors are being thrown.

    Thanks

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by hifigrafix View Post
    The query above should output the song list and order them by song title (obviously) ...
    It's not that obvious... if you put song_title between quotes

  3. #3
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh.. nice.. so - this started happening right after I migrated this script to a new server.. those were originally "tildes" (the key under left hand esc). I wonder what would cause them to be transformed to single quotes / apostrophes.

    thanks for the heads up.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,329
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by hifigrafix View Post
    those were originally "tildes" (the key under left hand esc).
    i'm betting they were actually "backticks" (the key under left hand esc)

    ~ = tilde
    ` = backtick

    and they "transformed to single quotes" when somebody typed them in wrong

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by r937 View Post
    and they "transformed to single quotes" when somebody typed them in wrong
    Not necessarily. It once happened to me when I copy&pasted a query. I don't remember where I pasted it (something like Notepad, or directly in a webbased file management editing window) but when I saved it and ran the script, the backticks had become simple quotes...

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,329
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    i'll bet it was microsoft word, lol
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Could be


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •