Question : How to Select a Single Record from a MySql database when DISTINCT doesn't work

Greetings,

I have a database of CD's that I sell on my website. My database table is 'Flat' with no relational fields or tables. (I Know...) The Table contains a Title field and a SKU field. (Among many others) I am trying to generate a query that will return only 1 record per unique Title.  However I also need it to return the SKU for that record.

I have tired to use DISTINCT but I always end up with all the 'Titles' because each SKU is NOT unique even for the same Title... (yea Again I know, Long Story)

Anyway the database contains over 300,000 records and I am not in a position to make any changes to the database structure. There is just way too much code that uses this data base in its current form.

Any help would be appreciated. I am not a SQL guru or any other kind of guru for that matter, and would like some ideas or pointers.

Thanks in advance,

rrbecker

Answer : How to Select a Single Record from a MySql database when DISTINCT doesn't work

Exactly as I wrote in my original answer, but use Min instead of First.

Not this:
   SELECT Title, First(SKU) as SomeSKU from YourTable GROUP BY Title;

but this:
   SELECT Title, Min(SKU) as SomeSKU from YourTable GROUP BY Title;

--
Graham

Random Solutions  
 
programming4us programming4us