0

Dear All,

I'm facing a problem when using DISTINCT in mysql. Please refer my database design below.

id  lang    album   singer  title   family  writer  song    hits

In my db i want distinct title and the id from the db.
I'm trying the following code. But it only fetching the results but not the id. If i try its again displaying all the records.

Now i'm trying to display the results using query

SELECT DISTINCT `title` FROM `songs` WHERE `lang` = 'Telugu'

If i try this

SELECT id, DISTINCT title FROM songs WHERE lang = 'Telugu'

I'm getting nothing from the db.

Please help me which this. Thanks in advance.

Edited by pritaeas: Moved.

4
Contributors
6
Replies
8
Views
4 Years
Discussion Span
Last Post by code739
1
SELECT DISTINCT id, title FROM songs WHERE lang = 'Telugu'

should work. If not, you can always use GROUP BY.

Votes + Comments
Helped me to learn new thing in mysql i.e group by
0

Its will not work i guess because id is the primary key. So that it always unique. Can u elabrate the GROUP BY for my example if possible ?

0

Can you elaborate on exactly what information you are trying to retrieve? If you do not include the id in your query, you will get a distinct list of titles. However, you want to know the ID of each distinct title. So, if you add in the ID column in your query, you will get that information.

I am not clear on what you are trying to get in your results.

0

Dear JorgeM,

I'm trying to get the id of the distinct elements. if i say
SELECT id, DISTINCT title FROM songs WHERE lang = 'Telugu'
Its showing all the records from the table. I want only id's of the perticular distinct titles. Please help me

Edited by rayidi

1

how about select id from songs where lang='Telugu' group by title

Votes + Comments
Worked gr8 :) thnx alooooooooooooot
This question has already been answered. 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.