|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello,
I have a table called Products with columns ID (Primary key), Names, Category, Store and Vendor. I want to get the unique names along with their ID that fall under Category T, so I tried the following, SELECT DISTINCT Names, ID FROM Products WHERE (Category = 'T') But it doesn’t seem to work. Then I tried SELECT statement with DISTINCT(Names), but it didn’t work It works if I removed ID column from the SELECT statement. Any idea what is wrong with the above query? How do I run Distinct on one column but return 2 columns? Thank you, Joe |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
If you have multiple IDs for the same name, what do you want to return?
Here is one way: SELECT Names, MAX(ID) FROM Products WHERE Category = 'T' GROUP BY Names; You can replace MAX with MIN if you want to retrieve the MIN id. -- Plamen Ratchev http://www.SQLStudio.com |
|
![]() |
| Outils de la discussion | |
|
|