ccking
ccking

Reputation: 1

Selecting rows which have different values

I want to select rows which have 10 different soru_id from end of the table. It has to return only red marked rows. Table structure and red marked rows are in picture below. How can i do it?
http://i47.tinypic.com/2132iir.jpg

Upvotes: 0

Views: 67

Answers (1)

Chandu
Chandu

Reputation: 82903

Assuming the soru_id decides the beginning/end of the table

Try this:

SELECT DISTINCT soru_id
  FROM <YOUR_TABLE>
 ORDER BY date_created DESC 
 LIMIT 10;

In case you need the full row instead of soru_id alone. then try this:

SELECT *
FROM <YOUR_TABLE> a
JOIN
  ( SELECT soru_id,
           MAX(date_created) date_created
   FROM <YOUR_TABLE>
   GROUP BY soru_id LIMIT 10) b ON a.soru_id = b.soru_id
AND a.creation_date = b.creation_date

Upvotes: 1

Related Questions