I have a database like this:
banner | image | date
------------------------------
123_first | xxxxx | date
123_second | xxxxx | date
134_foo | xxxxx | date
134_foo | xxxxx | date
134_bar | xxxxx | date
I need to get:
banner | image | date
-----------------------------
134_foo | xxxxx | date
134_bar | xxxxx | date
When I select a specific ID (the 134). So I need to get all the banners id only on the first occurrence of each one.
I'm using this PDO statment but it doesn't return anything:
$sth = $dbh->prepare('SELECT `banner` FROM `abanners` WHERE `banner` LIKE ? ORDER BY `date` DESC GROUP BY `banner`');
$sth->execute(array($user["id"] . "%"));
The result should be:
Array('134_foo', '134_bar');
How can I fix the problem?