Long old UPDATE statement

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

    #1

    Long old UPDATE statement

    I have the following SQL which gives me the row Im after

    SELECT *
    FROM staff, staffemails
    WHERE staff.users_use rname='$user'
    and staff.staff_id = staffemails.sta ff_id

    thing is I now want to perform an update on the result of this query. Ive tried

    UPDATE staffemails
    SET is_registered ='0'
    WHERE staff.users_use rname = '$user'
    and staffemails.sta ff_id = staff.staff_id

    But that doesnt work!

    Any ideas????
  • Randy Day

    #2
    Re: Long old UPDATE statement

    David wrote:[color=blue]
    >
    > I have the following SQL which gives me the row Im after
    >
    > SELECT *
    > FROM staff, staffemails
    > WHERE staff.users_use rname='$user'
    > and staff.staff_id = staffemails.sta ff_id
    >
    > thing is I now want to perform an update on the result of this query. Ive tried
    >
    > UPDATE staffemails
    > SET is_registered ='0'
    > WHERE staff.users_use rname = '$user'
    > and staffemails.sta ff_id = staff.staff_id[/color]

    If is_registered is numeric, get rid of the quotes.
    Otherwise I can't see anything obvious.
    [color=blue]
    >
    > But that doesnt work!
    >
    > Any ideas????[/color]


    --
    Remove any occurrence of the letter 'x'
    from my email address to send me email.

    Comment

    • Randy Day

      #3
      Re: Long old UPDATE statement

      David wrote:[color=blue]
      >
      > I have the following SQL which gives me the row Im after
      >
      > SELECT *
      > FROM staff, staffemails
      > WHERE staff.users_use rname='$user'
      > and staff.staff_id = staffemails.sta ff_id
      >
      > thing is I now want to perform an update on the result of this query. Ive tried
      >
      > UPDATE staffemails
      > SET is_registered ='0'
      > WHERE staff.users_use rname = '$user'
      > and staffemails.sta ff_id = staff.staff_id[/color]

      If is_registered is numeric, get rid of the quotes.
      Otherwise I can't see anything obvious.
      [color=blue]
      >
      > But that doesnt work!
      >
      > Any ideas????[/color]


      --
      Remove any occurrence of the letter 'x'
      from my email address to send me email.

      Comment

      • Jonck van der Kogel

        #4
        Re: Long old UPDATE statement

        Looks to me like you left out the staff table in your UPDATE clause,
        so you should be getting the following error message if you ran that
        query in the MySQL monitor:
        ERROR 1109: Unknown table 'staff' in where clause

        The correct statement should be:
        UPDATE staffemails, staff
        SET is_registered = '0'
        WHERE staff.users_use rname = '$user'
        AND staffemails.sta ff_id = staff.staff_id;

        From the looks of your query syntax you're trying to run this query
        from something else than the monitor which is probably why you're not
        getting a very descriptive error message. It's always a good idea to
        do a trial run of your query in the MySQL monitor. if it works there,
        then at least you know your syntax is proper.

        All the best, Jonck

        Randy Day <randy.day@shaw .cax> wrote in message news:<3FF087BA. 7CEC072C@shaw.c ax>...[color=blue]
        > David wrote:[color=green]
        > >
        > > I have the following SQL which gives me the row Im after
        > >
        > > SELECT *
        > > FROM staff, staffemails
        > > WHERE staff.users_use rname='$user'
        > > and staff.staff_id = staffemails.sta ff_id
        > >
        > > thing is I now want to perform an update on the result of this query. Ive tried
        > >
        > > UPDATE staffemails
        > > SET is_registered ='0'
        > > WHERE staff.users_use rname = '$user'
        > > and staffemails.sta ff_id = staff.staff_id
        > >
        > > But that doesnt work!
        > >
        > > Any ideas????[/color][/color]

        Comment

        • Jonck van der Kogel

          #5
          Re: Long old UPDATE statement

          Looks to me like you left out the staff table in your UPDATE clause,
          so you should be getting the following error message if you ran that
          query in the MySQL monitor:
          ERROR 1109: Unknown table 'staff' in where clause

          The correct statement should be:
          UPDATE staffemails, staff
          SET is_registered = '0'
          WHERE staff.users_use rname = '$user'
          AND staffemails.sta ff_id = staff.staff_id;

          From the looks of your query syntax you're trying to run this query
          from something else than the monitor which is probably why you're not
          getting a very descriptive error message. It's always a good idea to
          do a trial run of your query in the MySQL monitor. if it works there,
          then at least you know your syntax is proper.

          All the best, Jonck

          Randy Day <randy.day@shaw .cax> wrote in message news:<3FF087BA. 7CEC072C@shaw.c ax>...[color=blue]
          > David wrote:[color=green]
          > >
          > > I have the following SQL which gives me the row Im after
          > >
          > > SELECT *
          > > FROM staff, staffemails
          > > WHERE staff.users_use rname='$user'
          > > and staff.staff_id = staffemails.sta ff_id
          > >
          > > thing is I now want to perform an update on the result of this query. Ive tried
          > >
          > > UPDATE staffemails
          > > SET is_registered ='0'
          > > WHERE staff.users_use rname = '$user'
          > > and staffemails.sta ff_id = staff.staff_id
          > >
          > > But that doesnt work!
          > >
          > > Any ideas????[/color][/color]

          Comment

          • David

            #6
            Re: Long old UPDATE statement

            sorry I should have said its not numeric, it contained within a set.

            the problem as Ive since discovered it the UPDATE statement, as far as
            Im aware cannot work with more than one table!

            Randy Day <randy.day@shaw .cax> wrote in message news:<3FF087BA. 7CEC072C@shaw.c ax>...[color=blue]
            > David wrote:[color=green]
            > >
            > > I have the following SQL which gives me the row Im after
            > >
            > > SELECT *
            > > FROM staff, staffemails
            > > WHERE staff.users_use rname='$user'
            > > and staff.staff_id = staffemails.sta ff_id
            > >
            > > thing is I now want to perform an update on the result of this query. Ive tried
            > >
            > > UPDATE staffemails
            > > SET is_registered ='0'
            > > WHERE staff.users_use rname = '$user'
            > > and staffemails.sta ff_id = staff.staff_id[/color]
            >
            > If is_registered is numeric, get rid of the quotes.
            > Otherwise I can't see anything obvious.
            >[color=green]
            > >
            > > But that doesnt work!
            > >
            > > Any ideas????[/color][/color]

            Comment

            • David

              #7
              Re: Long old UPDATE statement

              sorry I should have said its not numeric, it contained within a set.

              the problem as Ive since discovered it the UPDATE statement, as far as
              Im aware cannot work with more than one table!

              Randy Day <randy.day@shaw .cax> wrote in message news:<3FF087BA. 7CEC072C@shaw.c ax>...[color=blue]
              > David wrote:[color=green]
              > >
              > > I have the following SQL which gives me the row Im after
              > >
              > > SELECT *
              > > FROM staff, staffemails
              > > WHERE staff.users_use rname='$user'
              > > and staff.staff_id = staffemails.sta ff_id
              > >
              > > thing is I now want to perform an update on the result of this query. Ive tried
              > >
              > > UPDATE staffemails
              > > SET is_registered ='0'
              > > WHERE staff.users_use rname = '$user'
              > > and staffemails.sta ff_id = staff.staff_id[/color]
              >
              > If is_registered is numeric, get rid of the quotes.
              > Otherwise I can't see anything obvious.
              >[color=green]
              > >
              > > But that doesnt work!
              > >
              > > Any ideas????[/color][/color]

              Comment

              Working...