posting only one result if multiple results are equal

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chrisflip8
Forum Newbie
Posts: 2
Joined: Wed Jul 06, 2011 8:43 am

posting only one result if multiple results are equal

Post by chrisflip8 »

Basically, I have a form that allows users to upload information to a mysql database. They input the last name of a person and write a comment about them. If people write about the same person, there will be multiple rows in the database with that same last name in the "name" field. Now I have it set up so people search by letter. So if there are 10 rows in the database with Smith as the last name, I don't want Smith to show up 10 times after the search. How can I get just one Smith to show up?? I'm using this a statement like this

SELECT lastname from tablename where lastname like 'S%' ... but obviosuly this gets me every row with a last name starting with S and duplicates if there is the same last name. PLEASE HELP!!

Thanks in advance.

Chris
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: posting only one result if multiple results are equal

Post by Celauran »

Code: Select all

SELECT lastname FROM tablename WHERE lastname LIKE 'S%' GROUP BY lastname
chrisflip8
Forum Newbie
Posts: 2
Joined: Wed Jul 06, 2011 8:43 am

Re: posting only one result if multiple results are equal

Post by chrisflip8 »

Wow, that simple. Thank you so so much!!
Post Reply