0

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

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

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

asked Jul 18, 2013 at 10:55
2
  • Please add your table structure and some data to explain your question.Also please clarify your question. Commented Jul 18, 2013 at 11:01
  • please show example output - both for the undesired and desired query results. This will clarify your question Commented Jul 18, 2013 at 11:16

1 Answer 1

2

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.

answered Jul 18, 2013 at 11:06
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.