rajeev kumar

rajeev kumar

  • NA
  • 141
  • 13.5k

How to get all friend request sent using Join in SQL server

Sep 15 2017 2:31 AM
Hello sir, i need help with join in sql. i have 2 table 1st is tbl_register amd 2nd is request.
 
  1. bl_register  
  2.     
  3. UserID     f_name      Designationnm    Comapny_name  
  4. 1      aaa                 CEO             Apple  
  5. 2      Rajeev      General manager          Dell  
  6. 3      upendra     Managing director        Dell  
  7. 4      soumendr        Vice president      lenovo  
  8. 9      Suneal      Managing director       Apple  
  9. 8       asa                CEO             Apple  
  10.     
  11. request table  
  12.     
  13. req_from_id req_to_id   req_status  
  14. 2              9               0  
  15. 3              9               0  
  16. 4              9               0  
  17. 2              8               0  
  18. 2              1               0  
 i need output like this.
 
  1. f_name       Designationnm   Comapny_name  UserID    req_from_id  
  2. aaa  aa             CEO            Apple     1             2  
  3. Rajeev          General manager    Dell      2             9  
  4. Suneal          Managing director  Apple     9             2  
  5. asa               CEO              Apple     8             2  
 What I have tried:
 
  1.  select distinct   
  2. tb1.UserID,tb1.f_name,tb1.Designationnm,tb1.Comapny_name,tb2.req_from_id        
  3. from Tbl_register tb1   
  4. left join  
  5. tbl_friend_and_match_request tb2  
  6. on   
  7. tb1.UserID = tb2.req_to_id  
  8. where   
  9. Comapny_name like '%apple%' or Designationnm like '%Managing director%'  
But it gives me output like this :
  1. UserID  f_name Designationnm  Comapny_name   req_from_id
  2. 1   aaa          CEO            Apple           2  
  3. 3   upendra  Managing director   Dell           NULL  
  4. 8   asa          CEO            Apple           2  
  5. 9   Suneal  Managing director   Apple           2  
  6. 9   Suneal  Managing director   Apple           3  
  7. 9   Suneal  Managing director   Apple           4  
 
 
 
 
 
 
 

Answers (1)