Insert query Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Limno
    New Member
    • Apr 2008
    • 92

    Insert query Problem

    insert into test (userid,questio n_id) ('1',select question_id from question ORDER BY RAND() LIMIT 2 )

    i need to insert values from question table with userid as 1.

    How can i solve ths problem

    Thanks in Advance
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    Use INSERT INTO TABLE.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      The INSERT INTO statement can take the result set of a SELECT query as the set of data it is supposed to insert. You simply replace the VALUES clause with a SELECT query.

      Try something more like:
      [code=sql]INSERT INTO `tbl_1`(`id`, `value`)
      SELECT 1, `value`
      FROM `tbl_2`
      ORDER BY RAND()
      LIMIT 10;[/code]

      Comment

      Working...