0

Database:
id name
1 Supriya
2 Himanshu
3 Deepika
4 Himanshu
5 sonu
6 Sonu

I am using name field to fetch the datas and my OUTPUT should be as

id name
2 Himanshu
4 Himanshu
1 Supriya
3 Deepika

what query should i use

4
Contributors
6
Replies
20
Views
3 Years
Discussion Span
Last Post by Ayrton C.
0

It isn't clear exactly what you're after here (based your sample output anyway). If you want duplicate names to be listed together you just need to use 'ORDER BY name' at the end of your query and it will be listed in alphabetical order by the name column.

0

Ayrton, what does that have to do with finding duplicates in the table as the post title mentions?

0

Hello,

It depends on what you are trying to do. If you are trying to find out if there are duplicates and how many then this will work:

select name, 
count(name) as NumberOfEntries
from database
group by name
having NumberOfEntries > 1

IF you are trying to find out the id's of the records with more than one entry then that can be done several ways depending on what you really want. Let us know.

0

since i am using this in php to fetch from database , when i select option from my dropdown with duplicate value should appears only once for eg Himanshu and when the Himanshu is selected then o/p should be as

id name
2 Himanshu
4 Himanshu

and when option supriya is selected then my o/p should be as

id name
1 Supriya

i'm trying to get the value in name field

Edited by My question

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.