Subject | UPDATE a table, but only rows matching a JOIN clause |
---|---|
Author | Matthias Hanft |
Post date | 2007-11-25T19:59:59Z |
Hello,
I have a result set generated by the following SELECT clause:
select l.*, b.status_wartung from lizenzen l
join bestellungen b on l.bestellung=b.venr
where l.ablaufjahr=2007 and l.ablaufversion=3 and l.bestellung starts with '2' and b.status_wartung=2
order by l.bestellung;
I now want to UPDATE the field l.ablaufjahr with 2008, but only
in the returned rows (which are dependant on b.status_wartung -
in another table!).
I guess I can't use JOIN within an UPDATE command - can I?!
It should be something like
update lizenzen l
set l.ablaufjahr=2008
join bestellungen b on l.bestellung=b.venr
where l.ablaufjahr=2007 and l.ablaufversion=3 and l.bestellung starts with '2' and b.status_wartung=2;
but, of course, JOIN doesn't work here.
So how can I use another table within an UPDATE command?
Thank you,
-Matt
I have a result set generated by the following SELECT clause:
select l.*, b.status_wartung from lizenzen l
join bestellungen b on l.bestellung=b.venr
where l.ablaufjahr=2007 and l.ablaufversion=3 and l.bestellung starts with '2' and b.status_wartung=2
order by l.bestellung;
I now want to UPDATE the field l.ablaufjahr with 2008, but only
in the returned rows (which are dependant on b.status_wartung -
in another table!).
I guess I can't use JOIN within an UPDATE command - can I?!
It should be something like
update lizenzen l
set l.ablaufjahr=2008
join bestellungen b on l.bestellung=b.venr
where l.ablaufjahr=2007 and l.ablaufversion=3 and l.bestellung starts with '2' and b.status_wartung=2;
but, of course, JOIN doesn't work here.
So how can I use another table within an UPDATE command?
Thank you,
-Matt