#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    22
    Rep Power
    0

    Numbering query result rows


    I use this code to number each number in a query result.


    Code:
    $query = "select @rownum:=@rownum+1 'rank', p.cid as id ,DATE_FORMAT(fecha, ' %W %D %M')AS bi,  descripcion AS bn from festivos p, (SELECT @rownum:=0) r order by fecha;";
    It works fine.

    However when I try to adapt it to a query that includes joins

    for example

    Code:
    $query = "select @rownum:=@rownum+1 'rank', p.festivos.cid as id, ....etc";
    #1054 - Unknown column 'p.festivos.cid' in 'field list'

    Any ideas how to solve this or is there a better way to number rows?
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,143
    Rep Power
    4274
    Originally Posted by Carrilo
    #1054 - Unknown column 'p.festivos.cid' in 'field list'
    look very closely at this error message

    it's telling you that something is wrong with this column name

    notice the two periods

    which part is the table name and which part is the column name?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    22
    Rep Power
    0
    OK Thanks! Seems obvious now

IMN logo majestic logo threadwatch logo seochat tools logo