Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My goal is to select rows from a mysql table, but according to certain column. Normal SELECT would be:

        SELECT, ti.userid,, ti.duedate, ti.datepaid, ti.subtotal, ti.taxrate, ti.paymentmethod, ti.notes AS invoicenotes,
        tii.invoiceid, tii.type, tii.description, tii.amount,, tc.firstname, tc.lastname, tc.companyname,, tc.address1, tc.address2,, tc.state,
        tc.postcode,, tc.phonenumber, tc.currency, tc.defaultgateway,, tc.taxexempt,
        tc.latefeeoveride, tc.overideduenotices, tc.separateinvoices, tc.disableautocc, tc.datecreated,
        tc.notes AS tcnotes,
          (SELECT GROUP_CONCAT(value) FROM tblcustomfieldsvalues WHERE AS vatid
        FROM tblinvoices ti
        LEFT JOIN tblinvoiceitems tii
        LEFT JOIN tblclients tc
        WHERE ti.status='Paid'
        AND ti.infakt_no IS NULL
        AND ti.paymentmethod='transferuj'
        ORDER BY ti.userid AND

But that kind of SELECT would split rows with same userid value. How to SELECT certain amount of rows and keep from separating userid?

share|improve this question
Please add your table structure and some data to explain your question.Also please clarify your question. – Abdul Manaf Jul 18 '13 at 11:01
please show example output - both for the undesired and desired query results. This will clarify your question – redguy Jul 18 '13 at 11:16

What i understand from your question is you need to group your result on the basis of user_id for that you can try this one

SELECT user_id,GROUP_CONCAT(id),GROUP_CONCAT(content) FROM tbl WHERE sth='sth' GROUP BY user_id LIMIT 10;

If you need anything else please comment and update in your question.

share|improve this answer
+1 for the GROUP_CONCAT – redguy Jul 18 '13 at 11:21
This is a beautiful answer. Nice! – dotancohen Jul 18 '13 at 12:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.