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

    Join Date
    Aug 2003
    Posts
    101
    Rep Power
    12

    How to normalised a table with data in it?


    Hi!

    I have the following table:

    USER Table
    --------------
    user id
    user name
    user group
    user location

    I would like to normalised it to

    USER2 TABLE
    -----------------
    user id
    user name
    group id
    location id

    GROUP TABLE
    ------------------
    group id
    group name

    LOCATION TABLE
    ---------------------
    location id
    location name
    What is the sql statement which could do this? Thank you.
  2. #2
  3. No Profile Picture
    Senior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Canada
    Posts
    308
    Rep Power
    11
    Use the CTAS (Create Table As Select) command of SQL, An example is given below:

    CREATE TABLE normal2
    AS
    SELECT a. userid, a.user_name, b.group_id,b.group_name
    FROM table1 a, table2 b
    WHERE a.user_id = b.user_id
    /

    It is only an example not the exact query you wanted, but you can modifiy it. Lets see how you accomplish your task.

    Regards,

IMN logo majestic logo threadwatch logo seochat tools logo