Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting records in Table

Status
Not open for further replies.

1994mkiv

Technical User
May 24, 2007
28
0
0
US
We have 2 tables LaborHed and LaborDtl. LaborHed contains EmployeeNum, ClockInDate ans some other info. LaborDtl contains EmployeeNum, ClockInDate, JobNum and some other info.
Example of LaborHed:
LaborHed.JPG

Example of LaborDtl:
LaborDtl.JPG


To show the records the qry I wrote is :
SELECT PUB_LaborHed.EmployeeNum, PUB_LaborHed.ClockInDate, PUB_LaborDtl.JobNum
FROM PUB_LaborHed LEFT JOIN PUB_LaborDtl ON (PUB_LaborHed.ClockInDate = PUB_LaborDtl.ClockInDate) AND (PUB_LaborHed.EmployeeNum = PUB_LaborDtl.EmployeeNum);
LaborHed_LaborDtl.JPG


Now you can see there are some records in LaborHed that Do not have any detail. I need to write a qry to delete all of these records from LaborHed.
 
Code:
delete
FROM PUB_LaborHed LEFT JOIN PUB_LaborDtl ON (PUB_LaborHed.ClockInDate = PUB_LaborDtl.ClockInDate) AND (PUB_LaborHed.EmployeeNum = PUB_LaborDtl.EmployeeNum)
[COLOR=blue]where PUB_LaborDtl.EmployeeNum IS NULL[/color]
Test it as a select first.

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
There is an error in the qry

"Specify the table containg the records you want to delete
 
Code:
delete [b]PUB_LaborHed.*[/b]
FROM PUB_LaborHed LEFT JOIN PUB_LaborDtl ON (PUB_LaborHed.ClockInDate = PUB_LaborDtl.ClockInDate) AND (PUB_LaborHed.EmployeeNum = PUB_LaborDtl.EmployeeNum)
where PUB_LaborDtl.EmployeeNum IS NULL
Test first.

The table name is optional if using only one table in the query.

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Error Again

"Could not Delete From Specified Table"


Thankyou for keep looking at the code
 
Access doesn't always resolve queries very well. Try something like:
Code:
delete PUB_LaborHed.*
FROM PUB_LaborHed 
WHERE ClockInDate Not In 
(SELECT ClockInDate FROM PUB_LaborDtl 
WHERE PUB_LaborHed.ClockInDate = PUB_LaborDtl.ClockInDate AND PUB_LaborHed.EmployeeNum = PUB_LaborDtl.EmployeeNum)


Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top