Insert ... Select...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lifesciencemedia

    #1

    Insert ... Select...

    I am new to mysql and would appreciate someone helping me out with this
    converting this statement from postgresql to mysql.

    INSERT INTO ossurjoinquesti ons SELECT *, RANDOM() as random_sort,
    trunc(114435546 0, 0) as instanceid FROM ossurcommonques tions WHERE tid =
    '3';

    So far I have

    INSERT INTO ossurjoinquesti ons( tid, question, ans1, ans2, ans3, ans4, ans5,
    corans, image_path, random_sort, instanceid )
    SELECT tid, question, ans1, ans2, ans3, ans4, ans5, corans, image_path
    FROM ossurcommonques tions
    WHERE tid = '3'

    What I am not sure how to do is add RAND() as random_sort or trunc($var,0)
    as instanceid.

    Thank you for any help.


  • Bill Karwin

    #2
    Re: Insert ... Select...

    lifesciencemedi a wrote:[color=blue]
    > What I am not sure how to do is add RAND() as random_sort or trunc($var,0)
    > as instanceid.[/color]

    RAND() is the MySQL equivalent of PostgreSQL's RANDOM() function.
    TRUNCATE() is the MySQL equivalent of PostgreSQL's TRUNC() function.

    See the documentation on the respective web sites:

    http://dev.mysql.com/doc/refman/5.0/...functions.html

    Regards,
    Bill K.

    Comment

    Working...