Re: nasty SQL query, please advise...
- From: "Maarten Wiltink" <maarten@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 20 Sep 2005 16:57:15 +0200
"swansnow" <schultz@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1127224435.032621.228340@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Three tables: clients, coverage, visits
> A client may have one or more coverages. A coverage may have one or
> more visits.
>
> Clients pk: clientID
> coverage pk: covID, fk:clientID
> visits pk: visitID, fk:covID
>
> The query is this:
> The visits table needs to store the client number for the client whose
> visit this is for (don't ask why...)
>
> I'm not sure how to express the SQL. Here's a beginning:
>
> UPDATE visits
> SET clientnum = (SELECT clientID from clients c
> LEFT JOIN coverage v on c.clientID = v.clientID
> LEFT JOIN visits t on v.covID = t.covID
> WHERE .....???? )
>
> I don't know what to put in the WHERE clause.
(visits.visitID = t.visitID). I think. You may need an alias on the
Visits table as referenced by the UPDATE query itself, to disambiguate
it from t.
What you want is to update only the record from where you started
joining.
Can't you UPDATE a JOIN directly? That way, you wouldn't need a WHERE
clause at all. I think.
Groetjes,
Maarten Wiltink
.
- Follow-Ups:
- Re: nasty SQL query, please advise...
- From: swansnow
- Re: nasty SQL query, please advise...
- References:
- nasty SQL query, please advise...
- From: swansnow
- nasty SQL query, please advise...
- Prev by Date: nasty SQL query, please advise...
- Next by Date: Re: nasty SQL query, please advise...
- Previous by thread: nasty SQL query, please advise...
- Next by thread: Re: nasty SQL query, please advise...
- Index(es):
Relevant Pages
|
|