We help IT Professionals succeed at work.

Need Sql Query

Tpaul_10
Tpaul_10 asked
on
219 Views
Last Modified: 2012-02-09
Experts,

Details are attached

Thanks for your help
Comment
Watch Question

Simone BBI & Reporting Analyst

Commented:
There seems to be no attachment ...

Author

Commented:
I am sorry, here it is
query.docx
Simone BBI & Reporting Analyst

Commented:
I think you're looking for something like this, but you have more than 5 results that are laptops, from the data you've shared:

SELECT [ORDER].OrderNumber, [ORDER].Paymode, OrderDetails.OrdDetails, OrderDetails.ACTIVE
FROM ORDER
INNER JOIN OrderDetails ON [ORDER].OrderNumber = OrderDetails.OrderNumber
WHERE [ORDER].Paymode = 6 AND OrderDetails.OrdDetails = 'Laptop'

Author

Commented:
Thanks for the quick reply.

The query should return order details with paymode “6” which has ONLY laptops.

For example : if you take ordernumber "1" and "7", it has both desktops and laptops and I shouldn't see those in my results.

And the query is not giving me the right results as per my attachment.

Thanks for your help
Simone BBI & Reporting Analyst

Commented:
Okay, I see what you need. How about this:


SELECT [ORDER].OrderNumber, [ORDER].Paymode, OrderDetails.OrdDetails, OrderDetails.ACTIVE
FROM [ORDER]
INNER JOIN OrderDetails ON [ORDER].OrderNumber = OrderDetails.OrderNumber
WHERE [order].paymode = 6 AND
orderdetails.orderid IN (SELECT orderid FROM orderdetails WHERE orddetails = 'laptop')
AND orderdetails.orderid NOT IN (SELECT orderid FROM orderdetails WHERE orddetails <> 'laptop')

Author

Commented:
THANKS again for your help, but this query still returns me the details which has both desktop and laptops with paymode 6.

Appreciate your help
Simone BBI & Reporting Analyst

Commented:
I have recreated the tables exactly as they are in your document, and these are the results I get from the second query:

OrderNumber Paymode     OrdDetails           ACTIVE
----------- ----------- -------------------- ------
3           6           Laptop               Yes
4           6           Laptop               Yes
8           6           Laptop               No
10          6           Laptop               Yes
11          6           Laptop               Yes

Author

Commented:
Yes, you are right and I am really really sorry, looks like I have messed up the data from the first table. Can I update this ticket with the correct data or do I need to submit another ticket?

Please let me know.
Simone BBI & Reporting Analyst

Commented:
Go ahead and update this one, and I'll see what I can do.

Author

Commented:
THANK YOU so much. Please find the details as an attachment.
Appreciate your help and response.

Also, please let me know how I can increase the points on this one.
query.docx
BI & Reporting Analyst
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
THANKS and appreciate all your help.
Simone BBI & Reporting Analyst

Commented:
You're very welcome!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.