473,569 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete records from main table if subtable is empty

74 New Member
I have tables setup with a main table for information and a subtable that records the "multiple" records for the main record. I have written a query to go in and find Null or "" values to delete records that somebody started and closed out of, but then I realized that it wont delete the main records that information is recorded in if the sub record only contains 1 New record, because they arent neccesarily Null or "".

Does anybody have any ideas about how to accomplish this. As always any help is appreciated.
Aug 2 '09 #1
6 4033
ADezii
8,834 Recognized Expert Expert
@kstevens
  1. What is the Main Table Name?
  2. What is the Child Table Name?
  3. What is the Name and Data Type of the Linking Fields in both Tables?
  4. Any other information that you think is relevant
  5. For each Record in the Main Table, if no Child Records exist, Delete the Record in the Main Table? Is this your question?
Aug 3 '09 #2
kstevens
74 New Member
@ADezii
This is correct. I was really looking for the criteria that i would need to put in a select query to show me the results, then i can delete the records from the select query. This is maintenance that would only be done by me, and wont involve other people.

1. tblOpenOrders
2. tblOpenOrderDet ails
3. tblOpenOrders.W orkOrder (Long Integer), tblOpenOrderDet ails.WorkOrderD et (Long Integer)
4. I really dont think anything else would be relevant.
5. Definately

Thanks for responding! :)
Aug 3 '09 #3
ADezii
8,834 Recognized Expert Expert
@kstevens
The following SQL should indicate the Records that have to be Deleted:
Expand|Select|Wrap|Line Numbers
  1. SELECT  * FROM tblOpenOrders
  2. LEFT JOIN tblOpenOrderDetails ON tblOpenOrders.WorkOrder = tblOpenOrderDetails.WorkOrderDet
  3. WHERE tblOpenOrderDetails.WorkOrderDet Is Null;
Aug 4 '09 #4
kstevens
74 New Member
I tried this approach.....th is only works when a sub record has been started, information entered, and deleted (only when the subtable shows 1 record...used empty record and a new record). It does not work if a subrecord has never been touched. I need to find the main records that only have "NewRecord" sub records.

When i use the term "NewRecord" i am referring to an "undirty" record....one that is waiting for information to be entered....not one that is blank.
Aug 4 '09 #5
ADezii
8,834 Recognized Expert Expert
@kstevens
The way I interpret this, kstevens, is that you wish to Delete any Main Record, but only for a Sub-Record which technically doesn't even exist except in Memory, for the conditions you specify ('NewRecord/Undirty'). Is my thinking correct on this matter?
Aug 4 '09 #6
kstevens
74 New Member
Yes....and when i say "undirty" (funny word, lol) i am referring to never has been dirty, or just never used.

How about this. What if i build the select query to pull related information from both tables, and just look in one of the fields (that should have information). Would the select query look at the related field (no, not the linking field) as a null value, or a newrecord.....I will try this later. My current query is just looking at the subrecord (table) not both together.....i think, i guess i better check on that too.
Aug 4 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
3812
by: asad | last post by:
Hi, i have some problem in showing data. I have two tables First table(containing Hosting categories) Second table(Containg catagories data lik url,keyword,description.....etc) I want to display catgories names from first table and then diffren catagories total records from second table, like this
16
16984
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then...
6
5539
by: xixi | last post by:
hi, i read from some of the post that if i want to delete a whole table using sql, i can use empty option to delete all the records but keep the table definition, how to do that? the reason i want this because i will get log full error for delete many records before commit. instead of increase the log file size, i would like to know other...
4
13769
by: dmisen | last post by:
I have data on air pollution coming from sources across the country, and control options for reducing pollution from each source. The example below shows data for: - 2 sources (plant_ID "001" and "008") - total tons of pollution emitted from each source (20 and 25 tons, respectively) - an ID code for the each control device that could be...
1
1918
by: shades234 | last post by:
I was wondering if you can run a delete query in one database, and have the action take place in another database. Namely, do something like Delete (fields) IN (Database location) FROM (specify Table) WHERE (criteria is met) Now, the reason i ask is a problem was set to me, and i really didn't have much say in the design aspect. but here...
1
4486
by: jpr | last post by:
Hello, My database has 5 tables. WHen I add data to one table, it runs an append query that copies three records to other 4 tables. The main table is MASTER. The data I copy are: ID, SSN and PURGE DATE. I would like to create a delete query that would delete all records in all tables that show a date older that the one in the PURGE...
6
11258
by: satish mullapudi | last post by:
Hi All, I am getting strange situation. These r the steps I have followed: 1. Created an EMPLOYEE table with around 14 fields & 688038 records. (so a large table indeed). 2. Tried to delete all the rows in the table using the traditional DELETE FROM EMPLOYEE stmt. It is taking around 53 secs to delete all the records. So I have done the...
0
1929
by: Richnep | last post by:
Hi all,. I have a small issue I would like to resolve with VBA. I have a form which it's fields are bound to a table. Within that form is a subform which is a subtable. Tables relationship is a one to many from the main table to the sub table.
3
2511
by: blakerrr | last post by:
Hi All, I have a strange situation that I can't figure out. The task is quite simple, delete a record from a table. Here is my situation: I have a form called Order Create which cycles through the parts in my database, run off of a table called Master BOM. In this form there is a subform called Order Data (not linked to the main form)...
0
7701
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.