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?
Best Answer
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 oneIf you need anything else please comment and update in your question.