Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 343
  • Last Modified:

Help with SELECT statement, need only one of each item, witch is representet in a table

I need to list of countries, from where, a customer has active orders, but only need the value once.

The SQL select i use:
SELECT DISTINCT
SupplierCountry.cCode,
Orders.SupID,
OrdersProducts.tn
FROM (((OrdersProducts INNER JOIN Orders ON OrdersProducts.orderID = Orders.orderID)
INNER JOIN suppliers ON Orders.SupID = suppliers.SupID)
INNER JOIN  SupplierCountry  on suppliers.SupCountry =  SupplierCountry.SupCountry)  
WHERE transportNo <> '' AND Orders. Customer = ‘" & request.form("Customer ") & "' ORDER BY SupplierCountry.cCode ASC

The Tables:

Orders
Customer      orderID      SupID
Aa      1000      1
Bb      1001      1
Cc      1002      1
Dd      1003      2
Ee      1004      3

OrdersProducts
tn      ItemID      orderID
100      A      1000
100      B      1000
100      C      1000
101      D      1002
102      E      1003

Suppliers
SupID      SupCountry
1      5
2      2
3      3
4      2
5      5

SupplierCountry
cCode      SupCountry
BE      1
DE      2
FR      3
UK      4
US      5

Result:
US
US
US

I was hoping for:
US

Naan_PLS
0
NaanPLS
Asked:
NaanPLS
  • 3
  • 2
2 Solutions
 
NaanPLSAuthor Commented:
Ok, For some reason is the suplierID colum missing, but It could be any value.

NaanPLS.
0
 
IronhoofsCommented:
Try to only select the country distinct:

SELECT DISTINCT
SupplierCountry.cCode,
FROM (((OrdersProducts INNER JOIN Orders ON OrdersProducts.orderID = Orders.orderID)
INNER JOIN suppliers ON Orders.SupID = suppliers.SupID)
INNER JOIN  SupplierCountry  on suppliers.SupCountry =  SupplierCountry.SupCountry)  
WHERE transportNo <> '' AND Orders. Customer = ‘" & request.form("Customer ") & "' ORDER BY SupplierCountry.cCode ASC

0
 
CluskittCommented:
SELECT DISTINCT SupplierCountry.cCodE
FROM Orders
INNER JOIN SupplierCountry  
ON oRDERS.SupID =  SupplierCountry.SupCountry
ORDER BY SupplierCountry.cCode ASC
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
NaanPLSAuthor Commented:
I get Error 800a0cc1 with both.
0
 
CluskittCommented:
Mine wasn't accurate anyway. I skipped over a table. It should be like this:

SELECT DISTINCT s1.cCodE
FROM Orders o1
INNER JOIN Suppliers s2
ON o1.SupID=s2.SupID
INNER JOIN SupplierCountry s1
ON s2.SupCountry =  s1.SupCountry
ORDER BY SupplierCountry.cCode ASC

This works on Access and MS SQL
0
 
NaanPLSAuthor Commented:
Sorry, You are both right, and I'm a B..... I....
The 800a0cc1 Error wasn't related to the Select, but a recordset variable.

Thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now