user1976505
user1976505

Reputation: 79

Retrieve records from 2 tables

I have 2 tables I want to select the records from the Requirement table that has RService and RSubService = 'No Requirement' in last 15 days and who corresponding MobileIT and PhoneIT in the table EnquiryMaster table are null or not entered

  EnquiryMaster       
   [EnquiryId]
  ,[Company]
  ,[HeadOfficeAddress]
  ,[ContactPersonIT]
  ,[EmailIT]
  ,[MobileIT]
  ,[PhoneIT]
  ,[date]



   Requirement-
   [RequirementID]
  ,[EnquiryID]
  ,[Company]
  ,[RService]
  ,[RSubService]
  ,[RDetails]
  ,[RDate]

Upvotes: 0

Views: 75

Answers (3)

Xordal
Xordal

Reputation: 1369

select *
  from dbo.EnquiryMaster as em
  left join dbo.Requirement as r
    on em.EnquiryId = r.EnquiryID
 where r.MobileIT is null 
   and r.PhoneIT is null
   and em.RService ='No Requirement'
   and em.RSubService ='No Requirement'
   and em.date >= dateadd(day, -15, getdate())

Upvotes: 2

Vaishali
Vaishali

Reputation: 439

    select * from EnquiryMaster e, Requirement r 
    where e.EnquiryId = r.EnquiryID 
    and RService = 'No Requirement'
    and RSubService = 'No Requirement'

Upvotes: 1

Vamsi Pamula
Vamsi Pamula

Reputation: 147

select * from EnquiryMaster em
inner join Requirement r on r.EnquiryId = em.EnquiryID
where r.MobileIT is null and r.PhoneIT is null and em.RSubService ='No Requirement'

Upvotes: 1

Related Questions