Filter unique data and Update (1 Viewer)

gaby

Registered User.
Local time
Yesterday, 17:25
Joined
Apr 14, 2011
Messages
11
I need to update a table using a query to reference the the records to be updated. The problem is that on the table there might be multiple record of the instance I need to update. I need to update just one and change it's status to SALE. I use a select query to retrieve a single record; this I'm able to do without problem. My problem starts when I need to combine that with the UPDATE. I use the query as the condition to the update without success. I I run the query by itself it would retrieve the appropriate data let's say for example to records; when combined I get the message that I'm to update let say 500 records! :eek: Obviously I'm not doing it right. Here is the code I'm using:

UPDATE CALL_REPORT SET CALL_REPORT.STATUS = "SALE"
WHERE EXISTS
(SELECT SalesnotinCALL_REPORT.[Session id], First(CALL_REPORT.Status) AS FirstOfStatus
FROM SalesnotinCALL_REPORT LEFT JOIN CALL_REPORT ON SalesnotinCALL_REPORT.[Session id] = CALL_REPORT.SessionID
GROUP BY SalesnotinCALL_REPORT.[Session id]);

I also tried a completely different approach by creating a FlagTable were I'll add the id of a record that was updated and when updating checking that if the ID exist then it will flag that one instance was already updated. But it didn't work either. It points out ambiguous outer joins.

UPDATE SalesnotinCALL_REPORT LEFT JOIN (CALL_REPORT RIGHT JOIN FlagTable ON CALL_REPORT.SessionID = FlagTable.Sessio_ID) ON SalesnotinCALL_REPORT.[Session id] = CALL_REPORT.SessionID SET CALL_REPORT.Status = "SALE", FlagTable.Sessio_ID = [CALL_REPORT].[SessionID]
WHERE (((FlagTable.Sessio_ID) Is Null) AND ((SalesnotinCALL_REPORT.[Session id])=[CALL_REPORT].[SessionID]));


I'll appreciate if someone could give me a hint on how to do this right.
Thanks:eek:
 
Last edited:

Guus2005

AWF VIP
Local time
Today, 01:25
Joined
Jun 26, 2007
Messages
2,641
records should appear only once in a table and each record should have a unique key.
why would you update only one occurence of several identical records?
 

gaby

Registered User.
Local time
Yesterday, 17:25
Joined
Apr 14, 2011
Messages
11
This file has call records. A call can repeat or have different status but basically the record is the same. What I'm doing here is correcting records were for some reason there was a mistake and the call wasn't marked as sale. If I change more than one instance then I'll duplicate the sale.
Thank you for looking at my problem!
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 19:25
Joined
Jan 23, 2006
Messages
15,385

gaby

Registered User.
Local time
Yesterday, 17:25
Joined
Apr 14, 2011
Messages
11
Thanks. I understand. Very Good Link.
This is a daily call report and although I'll like it to be different that is the way I receive the data.
 

Guus2005

AWF VIP
Local time
Today, 01:25
Joined
Jun 26, 2007
Messages
2,641
Gaby,

I think Guus2005 was quietly suggesting that your table structure(s) were an issue.
If Normalized, there wouldn't be multiple copies of identical records.

You mentioned Call records. Here is a link to a data model of a General Call Centre. It may not be suited to your needs, but may give you an idea of structures.

http://www.databaseanswers.org/data_models/call_centers/call_centers_physical_general_dezign.htm
Thank you for stepping in and clearing the air:D
 

Users who are viewing this thread

Top Bottom