I am listing item from a database, in an array of many database items. I know what I am trying to do can be done by having separate table, however for this requirement, i wanted to see if it is possible to do the following.
My code is:
$sql_list ="SELECT *
ORDER BY dateCreated DESC";
This returns an array of data in the table which is good, however I have multiple entries of the same item with different entities.
So what i want to be able to do is select one of each entry, by its most recently updated row of data.
Is this possible, or am i simply trying to cut corners?
Suppose you have ID unique field and YourITEM field then:
select * from YourTable t1 where id = (select id from YourTable t2 where t2.YourItem=t1.YourItem order by DateCreated desc, id desc limit 1)
If you don't need last DateCreated value in your select then just:
select distinct YourItem from YourTable;
You can use
SELECT DISTINCT [column] or
GROUP BY [column]
Something like this with LIMIT 1?
$sql_list ="SELECT * FROM ".$this->tables_rma." ORDER BY dateCreated DESC LIMIT 1";