Tpaul_10
asked on
Need Sql Query
Experts,
Details are attached
Thanks for your help
Details are attached
Thanks for your help
There seems to be no attachment ...
ASKER
I am sorry, here it is
query.docx
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'
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'
ASKER
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
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')
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')
ASKER
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
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
OrderNumber Paymode OrdDetails ACTIVE
----------- ----------- -------------------- ------
3 6 Laptop Yes
4 6 Laptop Yes
8 6 Laptop No
10 6 Laptop Yes
11 6 Laptop Yes
ASKER
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.
Please let me know.
Go ahead and update this one, and I'll see what I can do.
ASKER
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
Appreciate your help and response.
Also, please let me know how I can increase the points on this one.
query.docx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
THANKS and appreciate all your help.
You're very welcome!