ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 275k

How to get spare no from categories 1 table where not exist per same s

Mar 28 2021 5:11 PM

How to get spare no from categories 1 table where not exist per same spare no on table categories 2?

so i need to make select statement query select spare no from table categories 1 that have different categories
on table categories 2 per same spare no

as example spare no 1350 have category 5902 on table categories1 but on table categories2
i have same same spare no 1350 but have different categories as 7090 and 4020
then i select or display this spare no from table categories 1

as example spare no 1200 have category 5050 on table categories1 but on table categories2
i have same same spare no 1200 but have same categories as 5050 on table categories 2
so i don't need it or don't need to display it because it exist same sapre no and same category on table categories 2

so How to make select query give me expected result below ?

  1. create table #categories1  
  2.  (  
  3.  catId int identity(1,1),  
  4.  SpareNo int,  
  5.  CategoryId int,  
  6.  )  
  7.  insert into #categories1(SpareNo,CategoryId)  
  8.  values  
  9.  (1200,5050),  
  10.  (1350,5902),  
  11.  (1700,8070),  
  12.  (1990,2050),  
  13.  (7000,2030)  
  14.       
  15.  create table #categories2  
  16.  (  
  17.  catId int identity(1,1),  
  18.  SpareNo int,  
  19.  CategoryId int,  
  20.  )  
  21.  insert into #categories(SpareNo,CategoryId)  
  22.  values  
  23.  (1200,5050),  
  24.  (1200,5090),  
  25.  (1200,5070),  
  26.  (1350,7090),  
  27.  (1350,4020),  
  28.  (1700,8612),  
  29.  (1990,7575),  
  30.  (1990,2050),  
  31.  (7000,4200),  
  32.  (7000,4500)  
  33.   
  34.   
  35. expected result :  
  36. catId SpareNo CategoryId  
  37. 2      1350    5902  
  38. 3      1700    8070  
  39. 5      7000    2030  

Answers (1)