Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select rows with specified distinct columns

Status
Not open for further replies.

hakihara

Programmer
Apr 19, 2007
1
RO
Hello everybody, I have this problem: I need to select a number of rows from a table that differ only by a specified column(s).For example, I have this table:
Code:
Table1: Case Element Value
======  ------------------
        A    1       11   
        A    1       23   
        B    2       41   
        B    2       17
and I would like to obtain this table(composed of the rows that contain different values in the [Element] column. The returned rows are those found first):
Code:
Table2: Case Element Value
======  ------------------
        A    1       11   
        B    2       41
Thanks for your time :). I work with MSAccess.
 
There's nothing "first" in SQL. The order of a table is always undefined. (You can use ORDER BY to order the result table AFTER it has been created.)

So you'll have to decide if you want the smallest/highest etc value. E.g.:

[tt]SELECT "Case", "Element", MIN("Value")
FROM Table1
GROUP BY "Case", "Element"
[/tt]

Note that CASE, ELEMENT, and VALUE are all reserved words in SQL, that's why I've double quoted them above. (See for all full list of reserved words.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top