My issue is fairly simple to explain:
I need a query which selects the DISTINCT for a column, but I need to select other columns too, normally without DISTINCT. Can anyone show me such a query as an example?
It should be an universal query!
Thanks.
$sql = 'SELECT DISTINCT user_id FROM ' . DONATION_SECURITY_TABLE . "
$sql_where
ORDER BY payment_status ASC, user_id ASC";
I need to make this query select other stuff too, not just user_id distinct, I also need to select: donation_id, payment_status, pending_reason, txn_id, mc_gross and amount.
Sample table:
donation_id user_id mc_gross payment_status txn_id (has UNIQUE index)
1 4 5.00 Completed g54g4
2 5 10.00 Pending 54yhh
3 4 6.00 Pending 54yhg
4 7 15.00 Completed fdhgf
The query should return:
DISTINCT for user_id, SUM of mc_gross for the distinct-ed user_id, latest payment_status (would return Pending for user_id = 4).
This should work: