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?
jakubplusjakubplus
-
Please add your table structure and some data to explain your question.Also please clarify your question.Abdul Manaf– Abdul Manaf2013年07月18日 11:01:17 +00:00Commented Jul 18, 2013 at 11:01
-
please show example output - both for the undesired and desired query results. This will clarify your questionredguy– redguy2013年07月18日 11:16:47 +00:00Commented Jul 18, 2013 at 11:16
1 Answer 1
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
lang-sql