Wings2fly
Wings2fly

Reputation: 937

How to get a single row from the duplicate rows in mysql

I want to get only 1 row from the number of duplicate aspect_id(rows) returned.

SELECT rt.taxonomy_id,rt.iteration,ra.* FROM request_taxonomy rt 
inner join request_aspects ra ON ra.aspect_id = rt.request_aspects_id
                WHERE rt.requests_id = 6 and ra.section_name='Timeline'; 

Is there any way to get the distinct rows based on aspect_id?

Upvotes: 0

Views: 29

Answers (2)

phsaires
phsaires

Reputation: 2388

Use GROUP BY:

SELECT 
    rt.taxonomy_id,rt.iteration,ra.* 
FROM request_taxonomy rt 
        inner join request_aspects ra ON ra.aspect_id = rt.request_aspects_id
WHERE rt.requests_id = 6 and ra.section_name='Timeline'
GROUP BY aspect_id;

Upvotes: 1

Sumit Pandey
Sumit Pandey

Reputation: 448

GROUP BY can help you

SELECT rt.taxonomy_id,rt.iteration,ra.* 
FROM request_taxonomy rt 
inner join request_aspects ra ON ra.aspect_id = rt.request_aspects_id
WHERE rt.requests_id = 6 and ra.section_name='Timeline' 
GROUP BY aspect_id;

Upvotes: 1

Related Questions