Question
help with SELECT statement, GROUP BY & DISTINCT ASP/VB
Hi. Hope someone can help with my SELECT statement.
I have a customers table:
customerID
customername
address
...etc
An orders table:
orderID
customerID
deliveryaddress
deliverypostcode
...etc
A customer can obviously submit several orders and each of these orders may
have different addresses. I want to be able to provide the customer with
the option to auto-complete the order form by choosing a previously used
delivery address from a drop down menu on the order form page. However, I
would like to GROUP the delivery addresses by postcode so that the same
postcode (address) doesn't appear twice in the menu.
The problem I'm having is that I can only use GROUP BY on a recordset that
contains only one field - the field that I group by (the postcode!). Yet I
need ALL of the delivery address information in order to fill in the form.
I am very new to GROUP BY and someone also mentioned using DISTINCT but I'm
not sure how to do this.
I understand that I can create a query in my database that uses an INNER
JOIN to take related data from two separate tables/queries, but I'm not
entirely sure if that will work either on a GROUP BY or DISTINCT.
Hope someone can point me in the right direction! Thanks.
Regards
Nath.
I have a customers table:
customerID
customername
address
...etc
An orders table:
orderID
customerID
deliveryaddress
deliverypostcode
...etc
A customer can obviously submit several orders and each of these orders may
have different addresses. I want to be able to provide the customer with
the option to auto-complete the order form by choosing a previously used
delivery address from a drop down menu on the order form page. However, I
would like to GROUP the delivery addresses by postcode so that the same
postcode (address) doesn't appear twice in the menu.
The problem I'm having is that I can only use GROUP BY on a recordset that
contains only one field - the field that I group by (the postcode!). Yet I
need ALL of the delivery address information in order to fill in the form.
I am very new to GROUP BY and someone also mentioned using DISTINCT but I'm
not sure how to do this.
I understand that I can create a query in my database that uses an INNER
JOIN to take related data from two separate tables/queries, but I'm not
entirely sure if that will work either on a GROUP BY or DISTINCT.
Hope someone can point me in the right direction! Thanks.
Regards
Nath.
