I have a database table with multiple transaction records whose 'payee' column contains these kind of entries:
"DIRECT DEBIT PAYMENT TO AXA INSURANCE UK REF 551"<br>
"DIRECT DEBIT PAYMENT TO AXA INSURANCE UK REF 552"<br>
"DIRECT DEBIT PAYMENT TO AXA INSURANCE UK REF 554"<br>
"DIRECT DEBIT PAYMENT TO VODAFONE LIMITED REF 14"<br>
"DIRECT DEBIT PAYMENT TO VODAFONE LIMITED REF 15"<br>
"DIRECT DEBIT PAYMENT TO VODAFONE LIMITED REF 16"<br>
"DIRECT DEBIT PAYMENT TO GOOGLE IRELAND LTD REF 723"<br>
"DIRECT DEBIT PAYMENT TO GOOGLE IRELAND LTD REF 724"<br>
"DIRECT DEBIT PAYMENT TO GOOGLE IRELAND LTD REF 725"<br>
I would like to query the table in such a way as to get this list of "distinct" 'payee's:
"AXA INSURANCE UK"<br>
"VODAFONE LIMITED"<br>
"GOOGLE IRELAND LTD"<br>
My logic assumes I can execute a "distinct" type query incorporating a regex on the 'payee' column but I'm struggling.
Thank you nbk. Here is the pertinent line of code:
$query1 = mysql_query ("SELECT DISTINCT TRIM(REPLACE(SUBSTRING_INDEX(payee,'REF',1),'DIRECT DEBIT PAYMENT TO','')) FROM transactions", $Link);
...that gives empty results.
When I use this query, I get the dataset I published above:
$query1 = mysql_query ("SELECT DISTINCT payee FROM transactions WHERE date <= '$today' AND date >= '$backDate' and (payee like 'direct debit%' || payee LIKE '%standing order%') ORDER BY payee", $Link);