Hello. I'm wondering if I can get assistance with the DISTINCT keyword?
I've got a Table with 5-6 fields/information but 1000+ records. I want to select all fields but only use DISTINCT on one specific field.
There may be 1, 2, or 10+ records with a distinct code - I only want to choose the oldest record of each distinct code, but 5 unique/distinct records.
PROBLEM:
https://www.mysqltutorial.org/mysql-distinct.aspxIf I select multiple records, SELECT DISTINCT field1, Field2, etc.. it seems to combine "Field1, Field2" into one field and make a DISTINCT on THAT information, instead of just field1.
In all the tutorials I find I can only retrieve ONE field/information using DISTINCT, without retrieving all the information/fields.
Is it possible to select distinct on 1field, but retrieve ALL fields for that record?
An example of what I want: Select DISTINCT REF, * from Services ORDER BY `Services`.`TIMECHECK` ASC LIMIT 5;
*TIMECHECK* is a simple timestamp
Or do I need to do this in a 2-step process?
- get 5 records Distinct on the REF, sort by oldest records
- select all fields/columns of information for each unique record, (HOWEVER, I only want the oldest record).