如何从mysql中的重复行中获取单行

时间:2015-10-28 07:46:09

标签: mysql

我想从返回的重复aspect_id(行)数量中只获得一行。

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'; 

有没有办法根据aspect_id获取不同的行?

2 个答案:

答案 0 :(得分:1)

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;

答案 1 :(得分:1)

使用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;