Link to home
Start Free TrialLog in
Avatar of Tpaul_10
Tpaul_10Flag for United States of America

asked on

Need Sql Query

Experts,

Details are attached

Thanks for your help
Avatar of Simone B
Simone B
Flag of Canada image

There seems to be no attachment ...
Avatar of Tpaul_10

ASKER

I am sorry, here it is
query.docx
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'
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
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')
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
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
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.
Go ahead and update this one, and I'll see what I can do.
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
ASKER CERTIFIED SOLUTION
Avatar of Simone B
Simone B
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
THANKS and appreciate all your help.
You're very welcome!