samedi 28 février 2015

Selecting elements in alphabetical order in MySQL


Suppose I have a table called actor that has fields: actor_id, first_name, last_name. Currently, my table has entries like:


83 BEN WILLIS


152 BEN HARRIS


I would like to write a query that groups the table by first_name and if there are actors that share the same first name, only the row with the last name that comes first alphabetically will appear.


Meaning only 152 BEN HARRIS will appear and not 83 BEN WILLIS.


I tried to use the GROUP BY function, but I realize I needed something more. How would one go about doing this?





Aucun commentaire:

Enregistrer un commentaire