B
Bill Nevin
Hi, I'm looking to write a query that will select records distinctly on some
of the fields of the table, but I want to display all of the fields. The
problem is, when I add all of the fields to the SELECT statement, it includes
it into the DISTINCT statement. For example, if I have a table with six
fields and I want only distinct records for the first four fields, I could do:
SELECT DISTINCT [FIELD 1], [FIELD 2], [FIELD 3], [FIELD 4]
FROM tblExample;
This would yield, of course, only unique combinations of those fields. This
is what I want, unfortunately, I'd also like to show the last two fields, but
not to include them into the DISTINCT clause. If I give you an example table:
[FIELD 1] [FIELD 2] [FIELD 3] [FIELD 4] [FIELD 5] [FIELD 6]
<REF NUM>
APPLE JOHN 1/1/07 1/3/07 PAUL 0.80
1
APPLE JOHN 1/1/07 1/3/07 MIKE 0.10
2
APPLE JOHN 1/1/07 1/3/07 BILL 0.10
3
APPLE JOHN 2/1/07 2/3/07 PAUL 0.80
4
APPLE JOHN 2/1/07 2/3/07 MIKE 0.10
5
APPLE JOHN 2/1/07 2/3/07 BILL 0.10
6
APPLE JOHN 3/1/07 3/3/07 MIKE 0.60
7
APPLE JOHN 3/1/07 3/3/07 BILL 0.40
8
GRAPE PAUL 1/1/07 1/3/07 JOHN 1.00
9
I apologize if this isn't displayed fixed-width. If it doesn't and you're
curious to help, simply paste it into a text editor with a fixed-width font.
As you can see, however, that the above query would select records 1, 4, 7,
and 9 from this table. The exact records, I'd like to select. However, I'd
also like to see the [FIELD 5] and [FIELD 6] values from these records. If I
select them, in the above table's case, I would end up selecting all of the
records.
I hope you can see my issue. Does anyone know a way to do what I'm looking
for?
Thanks.
of the fields of the table, but I want to display all of the fields. The
problem is, when I add all of the fields to the SELECT statement, it includes
it into the DISTINCT statement. For example, if I have a table with six
fields and I want only distinct records for the first four fields, I could do:
SELECT DISTINCT [FIELD 1], [FIELD 2], [FIELD 3], [FIELD 4]
FROM tblExample;
This would yield, of course, only unique combinations of those fields. This
is what I want, unfortunately, I'd also like to show the last two fields, but
not to include them into the DISTINCT clause. If I give you an example table:
[FIELD 1] [FIELD 2] [FIELD 3] [FIELD 4] [FIELD 5] [FIELD 6]
<REF NUM>
APPLE JOHN 1/1/07 1/3/07 PAUL 0.80
1
APPLE JOHN 1/1/07 1/3/07 MIKE 0.10
2
APPLE JOHN 1/1/07 1/3/07 BILL 0.10
3
APPLE JOHN 2/1/07 2/3/07 PAUL 0.80
4
APPLE JOHN 2/1/07 2/3/07 MIKE 0.10
5
APPLE JOHN 2/1/07 2/3/07 BILL 0.10
6
APPLE JOHN 3/1/07 3/3/07 MIKE 0.60
7
APPLE JOHN 3/1/07 3/3/07 BILL 0.40
8
GRAPE PAUL 1/1/07 1/3/07 JOHN 1.00
9
I apologize if this isn't displayed fixed-width. If it doesn't and you're
curious to help, simply paste it into a text editor with a fixed-width font.
As you can see, however, that the above query would select records 1, 4, 7,
and 9 from this table. The exact records, I'd like to select. However, I'd
also like to see the [FIELD 5] and [FIELD 6] values from these records. If I
select them, in the above table's case, I would end up selecting all of the
records.
I hope you can see my issue. Does anyone know a way to do what I'm looking
for?
Thanks.