Delete Rows from T1 which are Not in T2

Hi
I've 2 Tables like below
T1
N1
N2
2
11
2
22
3
33
8
44
8
88
T2
N1
N2
2
22
8
88
If I Run Delete query, I must delete Rows from T1 which are Not in T2
For example, I must delete Rows 1,3,4 from T1
So how to write that delete query? Please advice

Delete from T1
Where not Exists (select * from T2 Where t1.N1=t2.N1 and t1.N2=t2.N2)
--or
Delete t
From t1 t
left JOIN t2 m
ON m.N1=t.N1 and m.N2=t.N2
WHERE m.N1 is null and m.N2 is null
--Or
;With mycte as
select N1,N2 from T1
Except
select N1,N2 from T2
Delete t
From t1 t
INNER JOIN mycte m
ON m.N1=t.N1 and m.N2=t.N2

Similar Messages

  • Delete records from tableA which are not in tableB

    Table A contains milions of records which is the best way to delete records from tableA which are not in tableB
    delete from tableA where empno not in (select empno from tableb)
    or
    delete from tableA where empno not exists (select empno from tableb
    where b.empno=a.empno)
    any help

    Hi
    If you can do this, do with this:
    create table tableC
    as select a.*
    from tableA a,
    (select empno from tableA
    minus
    select empno from tableB) b
    where a.empno = b.empno;
    drop table tableA;
    rename table tableC to tableA;
    Ott Karesz
    http://www.trendo-kft.hu

  • How to delete images from folder which are not in the database

    I am created windows form
    i wont to delete images from the folder where i have stored images but i only want to delete those images which are not in the data base.
    i don't know how it is possible . i have written some code
    private void button1_Click(object sender, EventArgs e)
    string connectionString = "Data Source";
    conn = new SqlConnection(connectionString);
    DataTable dt = new DataTable();
    cmd.Connection = conn;
    cmd.CommandText = "select * from tbl_pro";
    conn.Open();
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(dt);
    int count = Convert.ToInt32( dt.Rows.Count);
    string[] image1 = new string[count];
    for (int i = 0; i < count; i++)
    image1[i] = dt.Rows[i]["Image1"].ToString();
    string[] image2 = new string[count];
    for (int i = 0; i < count; i++)
    image2[i] = dt.Rows[i]["Image2"].ToString();
    var arr = image1.Union(image2).ToArray();
    string[] arrays;
    String dirPath = "G:\\Proj\\";
    arrays = Directory.GetFiles(dirPath, "*", SearchOption.AllDirectories).Select(x => Path.GetFileName(x)).ToArray();
    int b= arrays.Count();
    for (int j = 1; j <= b; j++)
    if (arrays[j].ToString() != arr[j].ToString())
    var del = arrays[j].ToString();
    else
    foreach (var value in del) // ERROR DEL IS NOT IN THE CURRENT CONTEXT
    string filePath = "G:\\Projects\\Images\\"+value;
    File.Delete(filePath);
    here error coming "DEL IS NOT IN THE CURRENT CONTEXT"
    I have to change anything .Will It work alright?
    pls help me
    Sms

    Hi Fresherss,
    Your del is Local Variable, it can't be accessed out of the if statement. you need to declare it as global variable like below. And if you want to collect the string, you could use the List to collect, not a string.  the string will be split to chars
    one by one.
    List<string> del=new List<string>();
    for (int j = 1; j <= b; j++)
    if (arrays[j].ToString() != arr[j].ToString())
    del.Add(arrays[j].ToString());
    else
    foreach (var value in del)
    string filePath = "G:\\Projects\\Images\\" + value;
    File.Delete(filePath);
    If you have any other concern regarding this issue, please feel free to let me know.
    Best regards,
    Youjun Tang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Sp_who2 -need only active sessions from users which are not the background sessions

    Hello,
    sp_who2 -need only active sessions from users which are not the background  sessions
    Please assist.
    Best regards,
    Vishal

    Its better to use DMV's to view only active sessions from users (spid>50) as mentioned by Shanky.
    You can do that using sp_who2 but it requires a bit of programming to list only user sessions.
    SELECT
    S.SESSION_ID,
    S.STATUS,
    S.HOST_NAME,
    C.CLIENT_NET_ADDRESS,
    CASE WHEN S.LOGIN_NAME = S.ORIGINAL_LOGIN_NAME THEN S.LOGIN_NAME ELSE S.LOGIN_NAME END LOGIN_NAME,
    S.PROGRAM_NAME,
    C.CONNECT_TIME,
    S.LOGIN_TIME,
    CASE S.TRANSACTION_ISOLATION_LEVEL
    WHEN 0 THEN 'UNSPECIFIED'
    WHEN 1 THEN 'READUNCOMITTED'
    WHEN 2 THEN 'READCOMMITTED'
    WHEN 3 THEN 'REPEATABLE'
    WHEN 4 THEN 'SERIALIZABLE'
    WHEN 5 THEN 'SNAPSHOT'
    ELSE CAST(S.TRANSACTION_ISOLATION_LEVEL AS VARCHAR(32))
    END AS TRANSACTION_ISOLATION_LEVEL_NAME,
    S.LAST_SUCCESSFUL_LOGON,
    S.LAST_UNSUCCESSFUL_LOGON,
    S.UNSUCCESSFUL_LOGONS,
    S.CPU_TIME AS CPU_TIME_MS,
    S.MEMORY_USAGE AS MEMORY_USAGE_PAGES,
    S.ROW_COUNT,
    S.PREV_ERROR,
    S.LAST_REQUEST_START_TIME,
    S.LAST_REQUEST_END_TIME,
    C.NET_TRANSPORT,
    C.PROTOCOL_TYPE,
    S.LANGUAGE,
    S.DATE_FORMAT,
    ST.TEXT AS QUERY_TEXT
    FROM
    SYS.DM_EXEC_SESSIONS S
    FULL OUTER JOIN SYS.DM_EXEC_CONNECTIONS C ON C.SESSION_ID = S.SESSION_ID
    CROSS APPLY SYS.DM_EXEC_SQL_TEXT(C.MOST_RECENT_SQL_HANDLE) ST
    WHERE
    S.SESSION_ID IS NULL
    OR S.SESSION_ID > 50
    ORDER BY
    S.SESSION_ID
    -Prashanth

  • While deleting project from CJ20N entries are not deleted from table PRPS

    Hi,
    I am deleting project from CJ20N then from PROJ table entries are getting deleted but WBS element entries are not deleted from table PRPS.
    Any deletion Flag should also be checked?
    Thanks in advance!
    Regards,
    Jyoti

    Hello,
    Thanks for reply !
    My problem is I am deleting project and WBS Elements from CJ20N but WBS element entries are not deleted from PRPS table.
    Why they are appearing in PRPS table and how it can be deleted?
    Thanks !

  • Deleting items from R/3 are not reflected into BW

    Hi all,
    We are facing an issue in the extraction of sales data. (2lis_11_vascl)
    If the items in a sales document are deleted in R/3 through the transaction VA02 then these changes are reflected into BW system.
    But if the items in a sales document are deleted through a background job in R/3 system then these changes are not triggering any delta records and are not transferred to BW system.
    How to enable the R/3 system to capture the change even when the records are deleted using a background job?

    The delta is not that simple....
    The delta is based on certain fields being changed. These fields are controlled by change pointers set into the tables..
    It is a long process but then the summary is :
    1. You have change pointers set for each table to capture changes... these change pointers write back to your dellta queue whenever these fields change. If you change a field which does not have a change pointer attached to it then the delta is not recognized..
    2. Also it depends on how you do the deletion in the background job - if you are just deleting from VBAP then this is not right - there will be a standard SAP function module for deletion which has to be used - the reason being that when you delete sales orders then the stock , allocations etc for the same have to be adjusted...
    3. You will have to find out the change pointers in place currently for the sales extractor ( I think it is ROOSOURCE ) and then identify the fields which are linked to this change pointer. You will then have to create either a new change pointer or change the existing one to capture these fields also and then the delta should start flowing...
    You can ask an ABAPER or a R/3 functional person about the way these change pointers are configured and setup in R/3

  • Itunes doesn't delete my old Podcasts which are not available anymore !

    Hi,
    Here's the problem:
    We used to podcast different feeds, it was working very well, each feed was available on Itunes with its own logo/graphic.
    Then we changed URLs and re-apply on Itunes: different URLs, Different Category (government&organizations: United Nations). But everyfeed was on Itunes: The old one+logo and the new one+logo. After useless attempts, I've decided to tell Itunes to delete the old URLs (to avoid any confusion, the old one is not updated anymore), giving the right ones. I repeated my request 2 times on the form(more than one month ago). Still no change.
    I don't know if I'm clear (because of my basic english, sorry by the way). Can someone from Itunes contact me ?
    The correct URLs are all here: http://www.unmikonline.org/pio/radiopodcast/podcastmain.htm
    Thanks for your attention.
    Olivier

    Your English is fine, Oliver, better than a lot of native speakers
    Which form did you use to ask them to remove the old feed? If you just contacted iTunes Support using the website, that might not work. What you need to do is go to your old feed's page in the iTunes store, hit the "Report a Concern" button, and in the "Choose Reason" list, select the "is mine and I would like it removed from the Music Store" option.
    Then you need to describe (in the message) that you have moved URLs and have new listings in the Store, and that you would like this old listing deleted. You need to do this for each of the old feeds.
    Good luck and let us know if you encounter any more problems.
    Peach

  • How do you delete songs from iphone5, that are not in your iTunes library on the computer?! I have the spot unchecked where it says show all music and I still have songs on my iPhone that I want gone, but they're not in my iTunes library...HELP

    I have a iPhone 5 with the most up to date software and I have songs appearing on my phone that I've deleted prior too from iTunes on the computer. How do I remove them from my phone, I've tried the left to right swipe and that just plays the songs! :/ Can anyone help me, I'd be forever grateful if I didn't have to go back to the store! I went I today abc he unchecked the show all music and there's still songs I don't want on my iPhone! :(

    The answer to the question in the title of the thread is yes, but it is not necessarily a good idea. At some point you are likely to find you need to restore your iPod for one reason or another, or it could be lost, stolen or damaged. If your songs aren't on your computer, and backed up too, then you will be less than happy.
    tt2

  • How do I delete photos on iPad which are not recognised by iMac

    Have hundreds of photos on ipad which I want to delete.  connected to iMac & went through the syncing process.  IMac via iTunes does not recognise the photos are on the iPad so how do I delete them please

    Thank you for your reply.
    I have tried both iPhoto and Image Capture but they do not recognise the photos on the iPad.  how do I get them off the iPad?

  • How do I delete songs from iPhone that are not in my iTunes library. "Swiping" to delete it does not work as the delete option does not appear.

    Just tried to remove all songs by changing synch entire music library to selected playlists, didn't select anything and says 0 songs at top, however the 5 **** songs that I'm trying to remove are still left on my phone!! This is so stupid but bugging me so much!!

    Hi, Jixx0615.
    Thanks for using Apple Support Communities.
    When you try to delete from a device running iOS 7, make sure to hold your finger on the song for a few seconds before swiping to the left. This should expose the red Delete button.
    Try Again,
    -Marcus

  • ODI to delete those members which are not present in the source file

    Hi John,
    Using ODI we can delete members by using delete option in the Operation column
    Fine. I would like to delete members from planning which are not there in the source file.
    For e.g if my source file has members A1,A2,A3,and A4 and Planning outline has A1,A2,A3,A4,A5 and A6. I would like to delete only A5 and A6.

    Hi John,
    Its only a one time process. The issue is, we have to concatenate two segments of the COA into one dimension in Planning. But if we concatenate it creates a cartesian product which is not the requirement. Only a particula value of segment 1 are to be joined with segment 2.
    E.g Company 1 is to be joined with Cost center 1.
    Company 2 with Cost center 2
    Company 1 should not get joined with Cost Center 2 and Company 2 with Cost Center1.
    So when we use ERPI and load the first outline it creates all the possibilities of the concatenation. So we would like to delete the unrequired members. If we have the values of the required members in a file, I would like to delete the unrequired members in the planning hierarchy.
    So would like to use the NOT IN function

  • How to delete the messages from SXMB_MONI which are already cancelled .

    Hi All,
    The messages were earlier in System error(Red flag) state so i cancelled it manually.
    I want to know how to delete the messages from sxmb_moni which are already cancelled manually using ctrl+f8.
    if not possible , then i want to see them in earlier state i.e.., in System error(Red flag).
    can any tell me the procedure of doing it.
    thanks
    Sai.

    Hi AmitSri,
    Thanks for u r reply,
    What is retention period, where can i find this option.
    And i don't have authorizations to sxmb_adm --> configure delete procedure
                                                                             --> Define interfaces for archiving and retention period.
    and to RSXMB_DELETE_MESSAGES in se38 , i don't have authorizations to run
    Is there any way to delete the messages or make them to System error( Red flag) which are manually cancelled.
    Thanks
    Sai.
    Edited by: sai_SHA on Aug 17, 2011 12:29 AM

  • I want to create stored procedure which will give output rows from "values that are passed as one parameter (comma seperated) to store procedure".

    Hello,
    I want to create stored procedure which will give output rows from "values that are passed as one parameter (comma seperated) to store procedure".
    Suppose , 
    Parameter value : person 1,person2,person3 
    table structure : 
    Project Name | officers 1 | officers 2
    here, officers 1 or officers 2 may contain names of multiple people.
    expected OUTPUT : distinct list(rows) of projects where person 1 or person 2 or person 3 is either officer1 or officer 2. 
    please explain or provide solution in detail 
    - Thanks

    Hi Visakh,
    Thanks for reply.
    But the solution you provided giving me right output only if officer 1 or officer 2 contains single value , not with comma seperated value.
    Your solution is working fine for following scenario : 
    Project 
    Officers 1
    Officers 2
    p1
    of11
    off21
    p2
    of12
    off22
    with parameter : of11,off22 : it will give expected output
    And its not working in case of :
    Project 
    Officers 1
    Officers 2
    p1
    of11,of12
    off21,off23
    p2
    of12,of13
    off22,off24
    with parameter : of11,off22 : it will not give any row in output
    I need patten matching not exact match :) 
    ok
    if thats the case use this modified logic
    CREATE PROC GetProjectDetails
    @PersonList varchar(5000)
    AS
    SELECT p.*
    FROM ProjectTable p
    INNER JOIN dbo.ParseValues(@PersonList,',')f
    ON ',' + p.[officers 1] + ',' LIKE '%,' + f.val + ',%'
    OR ',' + p.[officers 2] + ',' LIKE '%,' + f.val + ',%'
    GO
    Keep in mind that what you've done is a wrong design approach
    You should not be storing multiples values like this as comma separated list in a single column. Learn about normalization . This is in violation of 1st Normal Form
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • My deleted emails on iPhone 4s are not being deleted from server

    I'm facing a problem with my iPhone 4s when deleting emails. Unfortunately, they are not being deleted from the server. I tried setting the account in pop and imap with settings to delete from server and trash ticked. Still they keep on appearing in Outlook which is a double work to do. Please advise.

    I'm no expert by far, but have had issues with this before.
    IMAP should allow your iPhone to remove messages from the server.
    But have you made sure both the iPhone and Outlook are connecting via IMAP?
    If your iPhone does remove the messages from the server, but your computer is using POP, then the computer may download the email before it is removed form the server by your iPhone.
    This was my issue, that my computer had already downloaded the message, and POP does not check later if it is deleted.
    If you delete a message from Outlook does it disappear on the iPhone?
    Alternativly you may need to check the email server settings.
    Who is your email provider?
    They may be able to check if IMAP allows you to remove emails.

  • I have songs which are not selected in my library, but are still on my Iphone. How can they be deleted? Can they be deleted manually?

    I have songs which are not selected in my library, but are still on my Iphone. How can they be deleted? Can they be deleted manually?

    Ariana...
    so I assume there should be some track of them
    Yes.
    In the iTunes Store on the right under Quick Links click Purchased (new).
    You'll be able to re download past purchases for free if you are a resident of the U.S., and have iTunes 10.3 or later installed.
    Downloading past purchases from the App Store, iBookstore, and iTunes Store

Maybe you are looking for

  • Most reliable Mac Mini Model

    Any thoughts on what has been proven to be the most reliable Mini or a particular problem model. Hope to buy a used one soon. I'd prefer a PPC over an Intel just because i'd rather not run my older apps in Roseta. May be that not a real issue but i j

  • Query to generate Nested XML feed

    Hello, I use Oracle 11g R2 SOE.... I have two main tables COMMERCIALS_PROPERTIES (com_id number PK , com_size number, project_id number, com_type number) COM_PHOTOS (ID number PK , com_id number FK, content blob, mimetype varchar2) Please, note the f

  • Updation problem in custom infotypes.

    HI ALL, I have created two custom infotypes, and the process is that one infotype updates the other infotype. When i open the first infotype by pa30 and then open the second and changes some value which update the first infotype table. now when i go

  • How do you approve/forward an Expense Report thats fallen into ERROR?

    How do you approve/forward an Expense Report thats fallen into Systems Administration Action status -"ERROR" (or Expense Status Code)? When I try logging into IE Audit manager responsibility half the buttons described in the doc: http://download.orac

  • Problrm to connect 2005 B - with MSSQL 2005

    Can any one help me to solve the below problem I have installed 2005 B and MSSQL 2005 in server. When i try to login the application either from server / client i am getting the following error "Cluster mismatch -131-163" Pls help me on this