Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.

Respondida need join query

  • martes, 06 de marzo de 2012 12:41
     
     
    table1 and table2
    id            id
    1 3
    2 4
    3
    4


    select the records which are in table1 not in table2 by using join

    Naresh

Todas las respuestas

  • martes, 06 de marzo de 2012 12:44
     
      Tiene código

    Pls try

    select t1.* from table1 t1 left join table2 t2 on t1.id=t2.id
    where t2.id is null
    
    or
    
    select * from table1 where not exists(select 1 from table2 where table1.id=table2.id)

    vt


    Please mark answered if I've answered your question and vote for it as helpful to help other user's find a solution quicker


  • martes, 06 de marzo de 2012 13:25
     
     Respondida Tiene código

    Hi Naresh,

    Please see the example below along with query,

    DECLARE @TABLE1 TABLE(ID INT) 
    DECLARE @TABLE2 TABLE(ID INT) 
    INSERT INTO @TABLE1 VALUES (1),  (2) , (3) , (4)
    INSERT INTO @TABLE2 VALUES (3) , (4)
    
    
    SELECT  TABLE1.ID --,  TABLE2.ID 
     FROM @TABLE1  TABLE1
    	LEFT OUTER JOIN  @TABLE2 TABLE2  ON  TABLE1.ID =  TABLE2.ID	
     WHERE  TABLE2.ID IS NULL
    

    Thanks,
    Suresh
    Please use Mark or Propose as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    • Marcado como respuesta Naresh_a martes, 06 de marzo de 2012 16:32
    •