Solved

query problem _ delete unmatch items from table

Posted on 2013-01-09
5
193 Views
Last Modified: 2013-02-26
I am drawing a blank - I have two tables worth of data where I need to remove unmatached from table1.

I need to find all records from table 1(TA_FTIR) that doesn't exists in table2 (TD_FTIR) and remove them from table1.  

My current query seems to return only those records that are equal, I tried changing the join and the placement of the is Null without success.  What am I missing?

SELECT TA_FTIR.FTIR_MeasNo, TD_FTIR.FirstOfFTIR_BusName
FROM TD_FTIR LEFT JOIN TA_FTIR ON TD_FTIR.[FirstOfFTIR_BusName] = TA_FTIR.[FTIR_MeasNo]
WHERE (((TD_FTIR.FirstOfFTIR_BusName) Is Not Null));

Open in new window

0
Comment
Question by:Karen Schaefer
  • 2
  • 2
5 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 250 total points
ID: 38761074
use this query

SELECT TA_FTIR.FTIR_MeasNo, TD_FTIR.FirstOfFTIR_BusName
FROM TD_FTIR LEFT JOIN TA_FTIR ON TD_FTIR.[FirstOfFTIR_BusName] = TA_FTIR.[FTIR_MeasNo]
WHERE (((TD_FTIR.FirstOfFTIR_BusName) Is Null));
                                 

to delete those records, use this query

Delete * from
TA_FTIR , TD_FTIR
Where TA_FTIR.[FTIR_MeasNo] Not In
 (Select [FirstOfFTIR_BusName]  From TD_FTIR)
0
 

Author Comment

by:Karen Schaefer
ID: 38761101
Delete * from
TA_FTIR , QT_ARINC_BusDnld
Where TA_FTIR.[FTIR_MeasNo] Not In
 (Select [FirstOfFTIR_BusName]  From QT_ARINC_BusDnld)

Getting query to complex error.

K
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 38761103
you said another table, now you are using a query ???

change that query to make table query and then use the created table.
0
 

Author Comment

by:Karen Schaefer
ID: 38761181
I still have an issue with my from clause.

DELETE TA_FTIR.*
FROM
(
SELECT TA_FTIR.FTIR_BusName
FROM TA_FTIR, TD_ARINC_BusDnld
WHERE (((TA_FTIR.FTIR_Type) Like "A429" Or (TA_FTIR.FTIR_Type)="A629" Or (TA_FTIR.FTIR_Type)="A664" Or (TA_FTIR.FTIR_Type)="HFCI" Or (TA_FTIR.FTIR_Type)="ENET" Or (TA_FTIR.FTIR_Type)="DAR"))
GROUP BY TA_FTIR.FTIR_BusName
HAVING (((TA_FTIR.FTIR_BusName) Not In (Select [FTIR_BusName]  From TD_ARINC_BusDnld ))) as A INNER JOIN TA_FTIR ON A.FTIR_BusName = TA_FTIR.FTIR_MeasNo;

Open in new window

0
 
LVL 31

Assisted Solution

by:awking00
awking00 earned 250 total points
ID: 38764025
delete from ta_ftir
where not exists
(select 1 from td_ftir
 where td_ftir.keyfield = ta.ftir.keyfield)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now