Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: writing a DISTINCT statement while also pulling other field data from that sort.


Message #1 by "Shawn Contreras" <scontreras@s...> on Fri, 3 Jan 2003 23:10:18
Hi Shawn,

> Sorry for my lack of clarity. Let me try again:
>
> I have an Access database with about 50 different Column field names and
> about 200 rows.  Many of the rows have duplicate names in the
> "GenericProductName" column.  I am using Cold Fusion v4.5 to display my
> results.  I would like to do this: SELECT all the 200 row content in
> specific columns and display them. However, I do NOT want duplicated rows
of
> "GenericProductName", I only want those listed that are DISTINCT. However
I
> also want displayed those DISTINCT "GenericProductName" rows AND all their
> associated related column data.  Finally, then I want to display this in
> DESC order by "GenericProductName".
>
> Content in Database Example:
> Column Field Name
> ID  GenericProductName         BrandName            Class         Ply
> 1   Tissue Paper K             Kleenex               Nose           2
> 2   Tissue Paper P             Puffs                 Nose           1
> 3   Tissue Paper P             Puffs with Lotion     Nose           2
> 4   Toilet Paper C             Charmin               Butt wipe      1
> 5   Toilet Paper C             Charmin               Butt wipe      2
> 6   Toilet Paper C             Charmin               Butt wipe      3
>
> Output desired: To list only the Unique GenericProductName fields AND it's
> associated row data.
> Tissue Paper K              Kleenex               Nose
> Tissue Paper P              Puffs with Lotion     Nose
> Toilet Paper C              Charmin               Butt wipe
>
> I hope this helps...
>
> If I use:
> SELECT DISTINCT GenericProductName
> FROM ProdCat
>
> Then I only get the "GenericProductName" and not its associated row data.

How are you deciding which row of the data you want for each product - for
instance for Toilet Paper C you have 3 different Ply values?

If you don't care & just wanted the first entry for each GenericProductName,
you could use something like...

SELECT * FROM ProdCat
WHERE ID IN (SELECT FIRST(ID) AS ID FROM ProdCat GROUP BY
GenericProductName)
ORDER BY GenericProductName DESC;

HTH,

Chris


  Return to Index