The table has "Sales_Order_ID", "Sales_Order_Line_Number" and "Sales_Order_Line_staus" among other fields. I want to get "Sales_Order_ID", where each record for this "Sales_Order_ID" has the same "Sales_Order_Line_Status".
So, if every record for sales order X has a status of “closed”, I want to receive it. If in order Y there are three records with the status “closed” and one record with the status “open”, I do not want to retrieve it.
I tried:
SELECT DISTINCT s1.so_ID, s1.SO_line_status FROM sales_order_table s1 INNER JOIN sales_order_table s2 ON s1.so_id = s2.so_id AND s1.so_line_status = s2.so_line_status ORDER BY s1.so_id
Without success. The following seems to give the opposite of what I want:
SELECT DISTINCT s1.so_ID, s1.SO_line_status FROM sales_order_table s1 INNER JOIN sales_order_table s2 ON s1.so_id = s2.so_id AND s1.so_line_status <> s2.so_line_status ORDER BY s1.so_id
So I tried:
SELECT DISTINCT s1.so_ID, s1.SO_line_status FROM sales_order_table s1 INNER JOIN sales_order_table s2 ON s1.so_id = s2.so_id AND NOT s1.so_line_status <> s2.so_line_status ORDER BY s1.so_id
Without success.
Then I went completely noob and changed the type of connection, just hoping it worked. Am I closing here or totally cheating this wrong?
In addition, I understand that the above queries do not limit the results to a “closed” status, but I decided that if I could get one that returns only all the same status lines, I could then limit them to “closed”.
Sorry if this is unclear! If so, I’ll try to explain.
source share