SQL Statement

I need to run a report to show me products where pack A quantity is different from pack B quantity. I can run a basic SQL statement that brings me all products and then I run a conditional formating to show me where quantity A is different from quantity B.

Is there a way I can write it straight in the SQL statement so it only gives me where the quantities differ for each product?
Farah MohammedBuyerAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
SiddharthRoutConnect With a Mentor Commented:
Try this

select * from table where field1 <> field2

Sid
0
 
Muhammad Ahmad ImranConnect With a Mentor Database DeveloperCommented:
select * from packa
minus
select * from packb;
0
 
Farah MohammedBuyerAuthor Commented:
Just to confirm, I don't want to deduct pack A quantity from pack B quantity. I just need it to show me the products where pack A differs from pack B.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
tim_csConnect With a Mentor Commented:
SELECT
   *
FROM
   Table
WHERE
   PackA <> PackB
0
 
Farah MohammedBuyerAuthor Commented:
Thank you all for your help, especially Siddharthrout. Ran the statement and exactly what I needed.
0
 
wdosanjosCommented:
Check if this works for you:

SELECT *,
     CASE WHEN [PackAQty] = [PackBQty]
         THEN 'Equal'
         ELSE 'Different'
     END PackABQty
FROM [Products]

Open in new window

0
 
Farah MohammedBuyerAuthor Commented:
That is a different way of doing it, it would work if I wanted to show all products.
Sid's solution above was more what I needed, but I could use wdosanjos too.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.