×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jet Sql Statement - Select Distinct Multiple Columns

Jet Sql Statement - Select Distinct Multiple Columns

Jet Sql Statement - Select Distinct Multiple Columns

(OP)
Is this the best way to select multiple columns from a table that has a distinct order ID field?

CODE

SELECT Master.[OrderID], Max(Master.[customer]) AS MaxOfcustomer, Max(Master.[quotedPrice]) AS MaxOfquotedPrice
FROM Master
GROUP BY Master.[OrderID]; 

Thanks.

Swi

RE: Jet Sql Statement - Select Distinct Multiple Columns

If you have 'a distinct order ID field', then your data looks something like:

OrderID  customer   quotedPrice
1         23           43
2         23           21
3         23           67
4         45           53
5         76           75
...
 
and your Select statement does not make sense since you will get all records back.
There will be no MAX() when you GROUP BY OrderID, since OrderID is district/unique

If your OrderID is NOT unique, then this data:

OrderID  customer   quotedPrice
1         23           43
1         33           21
1         23           67
4         45           53
5         76           75
... 

would at least return:

1         33           67
 

when GROUP BY OrderID

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: Jet Sql Statement - Select Distinct Multiple Columns

(OP)
Hi,

Correct, my OrderID is NOT unique. Is there a more optimized way to do the query I posted or would you think this is a good approach?

Thanks.

Swi

RE: Jet Sql Statement - Select Distinct Multiple Columns

If that's what you need, and it is working the way you want, then 'this is a good approach'

I would just do this a lot shorter (eliminate superfluous pieces):

SELECT OrderID, Max(customer) AS MaxOfcustomer, Max(quotedPrice) AS MaxOfquotedPrice
FROM Master
GROUP BY OrderID;

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: Jet Sql Statement - Select Distinct Multiple Columns

(OP)
Thanks.

Swi

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close