Question : MINUS query -Why cannot work?

Hi Expert,

i try to perform the minus query in Microsoft SQL,but the errors occur.
The Example of Query is :
select * from (select distinct top 30 a1,a2,a3,a4 from a left join c where c.a1 = a.a1 order by Date Desc )A
MINUS
select * from (select distinct top 15 a1,a2,a3,a4 from a left join c where c.a1 = a.a1 order by Date Desc )B

The Error is :
Line 14: Incorrect syntax near 'minus'.


Anyone can help me?Thanks

From
jenney

Answer : MINUS query -Why cannot work?

Could you try this ?

SELECT * FROM
(
select distinct top 30 Payment.PaymentID,PaymentDetail.FileNo, Payment.PaymentNo, Payment.PaymentAmount, Payment.PaymentDate, ContactType.ContactType,
PaymentMethod.PaymentMethod, OtherAccount.AccountNo as OtherAccountNo, BankAccount.BankAccountNo as BankAccountNo,
Payment.ReferenceNo, Payment.ReleasedID
from Payment
left outer join Companies on Payment.PKID = Companies.Company_Counter  
left outer join PaymentMethod on Payment.PaymentMethodID = PaymentMethod.PaymentMethodID
left outer join ContactType on Payment.ContactTypeID = ContactType.ContactTypeID
left outer join BankAccount on Payment.BankAccountID = BankAccount.BankAccountID
left outer join PaymentDetail on PaymentDetail.PaymentID = Payment.PaymentID
left outer join Account as OtherAccount on Payment.OtherAccountID = OtherAccount.AccountID
order by Payment.PaymentDate Desc
)A
where  PaymentID not in (
      select top 15 Payment.PaymentID
      from Payment
      order by PaymentDate Desc
)

Random Solutions  
 
programming4us programming4us