Welcome to WebmasterWorld Guest from 54.234.38.8

Forum Moderators: open

Message Too Old, No Replies

MySQL - How to get DISTINCT or UNIQUE ?

How to get the 4th field to be DISTINCT among 4 fields?

     
1:35 am on Aug 27, 2012 (gmt 0)

New User

5+ Year Member

joined:May 17, 2007
posts: 17
votes: 0


Hi Masters,

I'm facing this delima that among 4 fields, I want the 4th field to be DISTINCT. How?

cno
cfname
cphone
cemailid -- DISTINCT

select DISTINCT cemailid, cno,cfname,cphone from rform (not working)

Kindly help me, Please...

Thanks in Advance.
Bharadwaj
2:05 am on Aug 27, 2012 (gmt 0)

Moderator from GB 

WebmasterWorld Administrator brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 30, 2002
posts:4842
votes: 1


This should work,

SELECT select cemailid, cno,cfname,cphone
FROM rform
GROUP BY cphone

See [dev.mysql.com...]
2:16 am on Aug 27, 2012 (gmt 0)

New User

5+ Year Member

joined:May 17, 2007
posts: 17
votes: 0


Thank You Bro,

No avail. I tried. 544 records on distinct on "cemailid" after adding another field, the record shoot upto 612.

Still trying.

Thanks for help.
2:31 am on Aug 27, 2012 (gmt 0)

Moderator from GB 

WebmasterWorld Administrator brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 30, 2002
posts:4842
votes: 1


GROUP BY field will most definitely give you distinct values. Maybe you should check for trailing newlines & spaces in those fields.
12:56 pm on Sept 16, 2012 (gmt 0)

New User

joined:Sept 14, 2012
posts:2
votes: 0


Better use Group by Syntax that using the keyword DISTINCT.
4:17 am on Sept 26, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 31, 2005
posts:1108
votes: 0


bortherhood of LAN is right in principle, but wrong in detail ;-), if you want to be distinct on cemailid you need to group on cemailid

SELECT select cemailid, cno,cfname,cphone
FROM rform
GROUP BY cemailid