cursor needed!?

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

    cursor needed!?

    Hello mysql experts,

    i would like insert only the first "value" from every member into the table
    members - but different counts exist in table members_action.

    UPDATE members set value1=
    (Select value from members_action where value1=
    (Select min(id) from members_action where
    members.member_ no=members_acti on.member_no));

    This works not, because i didn't get a result set, have anybody
    an example using a cursor for this problem in mysql if is necessary -
    i'm using 5.02alpha!?

    Many thanks,
    Christian
  • Bill Karwin

    #2
    Re: cursor needed!?

    christian wrote:[color=blue]
    > UPDATE members set value1=
    > (Select value from members_action where value1=
    > (Select min(id) from members_action where
    > members.member_ no=members_acti on.member_no));[/color]

    MySQL supports a SQL enhancement that permits a join in an UPDATE or
    DELETE statement. See the documentation on the UPDATE statement.

    Another method of solving this problem is to run a SELECT on
    members_action, with literal strings to form the necessary UPDATE
    statements to change records in the members table. Then run the result
    of this query as a SQL script.

    Regards,
    Bill K.

    Comment

    • Rich R

      #3
      Re: cursor needed!?


      "christian" <ozric@web.de > wrote in message
      news:1a3a333a.0 412310028.5cab5 710@posting.goo gle.com...[color=blue]
      > Hello mysql experts,
      >
      > i would like insert only the first "value" from every member into the[/color]
      table[color=blue]
      > members - but different counts exist in table members_action.
      >
      > UPDATE members set value1=
      > (Select value from members_action where value1=
      > (Select min(id) from members_action where
      > members.member_ no=members_acti on.member_no));
      >
      > This works not, because i didn't get a result set, have anybody
      > an example using a cursor for this problem in mysql if is necessary -
      > i'm using 5.02alpha!?
      >
      > Many thanks,
      > Christian[/color]

      This should work with your version of mysql:

      UPDATE members set value1 =
      (SELECT value FROM members_action WHERE members_action. member_no =
      members.member_ no AND
      id = (
      SELECT min(id) from members_action WHERE members_action. member_no =
      members.member_ no))

      Regards,
      Rich R.


      Comment

      Working...