Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2001
    Posts
    7

    Unanswered: Sequence no's in tables

    Hi,
    Could someone help me out? I have table with a field that is called unique_id and I need to write some SQL that will populate this field for me with a sequence from 1 to x. I have tried using the tid but unfortunately ingres is very limited with it's use of the tid within SQL. Does anyone have any suggestions about how to do this?

    Thanks,

    Mark

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    I am not familiar with ingres - but I believe you can do something like the following:

    Lets say you have a field called UID - which is your sequential id.

    Within your update statement do something like:

    update table set uid = (select max(uid) from table) + 1 where ...

  3. #3
    Join Date
    Feb 2002
    Posts
    2,232
    If that was not helpful - check out the following link:

    link

  4. #4
    Join Date
    Sep 2001
    Posts
    7
    Thanks for that, in the end I used the tid as the unique_id. I tried this originally but as part of a create table1 <table> as
    select tid,fileds... from table2.

    Tid wouldn't work with the create table statement but if I used the tid as part of an 'insert into ... select tid,fields.. from' then it seemed OK.

    Thanks,

    Mark

  5. #5
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    It's been a while since I used Ingres but you can generate a sequential key with increments of 1 if you implement something along the lines of:

    update yourtable
    set unique_id = (
    select count(*)
    from yourtable a
    where yourtable.tid >= a.tid)
    Last edited by Damian Ibbotson; 11-26-02 at 09:29.

Posting Permissions

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