Is it possible to get comma separated value of first n (say 10 rows of a column) rows using Mysql?
I have a query to get data greater than CURDATE(). And it will return more than 100 rows of result. What I want is, GROUP_CONCAT the first 10 rows of result.
This is my query:
SELECT GROUP_CONCAT(user_id) AS userids
FROM user_tasks
WHERE due_date > CURDATE() LIMIT 10;
am getting entire rows. I need first 10 rows only
Thanks
Use subquery:
SELECT
GROUP_CONCAT(user_id) AS userids
FROM
(SELECT
user_id
FROM
user_tasks
WHERE due_date > CURDATE()
LIMIT 10) AS users
You need to use a sub query to impose the limit, like this:
SELECT GROUP_CONCAT(sub_query.user_id) AS userids
FROM
(
SELECT user_id
FROM user_tasks
WHERE due_date > CURDATE()
LIMIT 10
) sub_query
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With