Skip to content
Advertisement

Retrieve start and last created date from a duplicated record

I have a table called mov_entrys and they have multiple historic records, in other words, duplicated records this is my main SQL statement

But the records are like this example:

In Laravel when a data is created the created_at and updated_at is the same data, but I want the start date and last date from this record that has the same ean13 data 7800003378198

The main query returns the record that I want but with the same data and I want the real created data and last data

if you think the record in the top, I want the return like this, if I use group I cant have like this

I try to make a subquery but I don’t know why always make an INFINITE load to return a data I think I’m doing something wrong, this is my query with subquery

When I execute this query alone it is working fine giving me the last record, what I’m doing wrong? This is my test query :

I mana

Advertisement

Answer

Consider aggregating on dates with MIN and MAX, grouping by all other SELECT columns. Below uses shorter aliases for readability:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement