Re: Assistance with the DISTINCT keyword
| From: | Aziz Hussain | Date: | Sun, 12 Nov 2023 11:48:18 +0000 |
| Subject: | Re: Assistance with the DISTINCT keyword | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-328309@lists.php.net to get a copy of this message | ||
Use group by
> On Nov 12, 2023, at 6:35 AM, gordonisnz@gmail.com wrote:
>
>
>
> 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.aspx
>
> If 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).
> --
>
> Gordon.