Sorting and limiting

Use the MQL ORDER BY clause to sort the output by one of the table columns, and use the LIMIT clause to limit the number of rows retrieved, together with the OFFSET clause to page through the data set. For LIMIT, the default limit is 1000 and you cannot increase the limit.

The ORDER BY and LIMIT clauses are available to list, aggregation, and distribution queries.

Here are some examples.

Response date in descending order, and only show the first ten responses

select fullname, responsedate, br_overall_experience, br_likely_to_recommend, br_likely_to_buy_next_prod, comments from survey where has_comment=1 order by responsedate desc limit 10

Response date in descending order, and only show the second ten responses

select fullname, responsedate, br_overall_experience, br_likely_to_recommend, br_likely_to_buy_next_prod, comments from survey where has_comment=1 order by responsedate desc limit 10 offset 10

Year column in the response date column

select responsedate.year, distribution_value, dist(br_overall_experience), dist(br_likely_to_recommend), dist(br_likely_to_buy_next_prod) from survey order by responsedate.year

Response date in descending order, and show only the first thirty results

SELECT fullname, responsedate, br_overall_experience, br_likely_to_recommend, comments, alert_type, alert_status FROM SURVEY ORDER BY responsedate DESC LIMIT 30

Average value of br_overal_interaction in descending order

SELECT unitid.name, count(*), avg(br_overal_interaction), avg(br_overall_experience), avg(br_likely_to_recommend), avg(br_likely_to_buy_next_prod) FROM SURVEY ORDER BY avg(br_overal_interaction) DESC