select a column of type INTEGER PRIMARY KEY magically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    select a column of type INTEGER PRIMARY KEY magically

    Is it possible to select a column of type INTEGER PRIMARY KEY without knowing its name? This also happens to be column zero in all my tables. I've played with lots of different syntaxes, to no avail. I was hoping for something compatible with SQLite like:[CODE=sql]SELECT * FROM tablename WHERE ROWID = n;
    # or
    SELECT * FROM tablename WHERE _ROWID_ = n;
    # or
    SELECT * FROM tablename WHERE OID = n;[/CODE]Thanks, all.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Are you trying to refer to the column without knowing its name.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      I've see this used before somewhere but I haven't tried it myself

      [CODE=mysql]SELECT k.column_name
      FROM information_sch ema.table_const raints t
      JOIN information_sch ema.key_column_ usage k
      USING(constrain t_name,table_sc hema,table_name )
      WHERE t.constraint_ty pe='PRIMARY KEY'
      AND t.table_schema= 'yourdatabase'
      AND t.table_name='y ourtable';[/CODE]

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by r035198x
        I've see this used before somewhere but I haven't tried it myself

        [CODE=mysql]SELECT k.column_name
        FROM information_sch ema.table_const raints t
        JOIN information_sch ema.key_column_ usage k
        USING(constrain t_name,table_sc hema,table_name )
        WHERE t.constraint_ty pe='PRIMARY KEY'
        AND t.table_schema= 'yourdatabase'
        AND t.table_name='y ourtable';[/CODE]
        Awesome! Thank you very much.

        Comment

        Working...