Selecting DISTINCT Records

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
amplifire
Forum Newbie
Posts: 23
Joined: Thu Jul 22, 2010 1:09 am
Location: India
Contact:

Selecting DISTINCT Records

Post by amplifire »

Hello everyone!

I Want to ask that how can i do this.

1) This is my table (StudentInfo) in database
Name Age Ph. No. Address
Abc 12 0000 Street1
Pqr 13 4444 Street2
Xyz 12 6666 Street3
Pqr 13 4444 Street2
Pqr 13 4444 Street2

2) I want to pick up DISTINCT records based on Age Field. However i can use
"SELECT DISTINCT Age FROM StudentInfo"

But this way i can only fetch the Age Field. How can I fetch the rest of the fields namely Name, Ph. No., Address.

Suggestions Appreciated
Regards
Last edited by amplifire on Mon Nov 22, 2010 9:08 am, edited 1 time in total.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Selecting DISTINCT Records

Post by Celauran »

Code: Select all

SELECT *, DISTINCT(Age) FROM Studentinfo
amplifire
Forum Newbie
Posts: 23
Joined: Thu Jul 22, 2010 1:09 am
Location: India
Contact:

Re: Selecting DISTINCT Records

Post by amplifire »

Thanx Celauran!!

I found it, should go like this
SELECT DISTINCT Age,Name,Address FROM StudentInfo.
Post Reply