Link to home
Start Free TrialLog in
Avatar of dimensionav
dimensionavFlag for Mexico

asked on

How to get correct data from a query?

HI

I have a table like this named Profiles:

!dMain, IdProfile, Qty
1                17        20
2                17        33
3                18        25
4                18        30
5                17        10
6                17         5

I just want to have the last added record per each IdProfile using SQL, something like this:

!dMain, IdProfile, Qty
4                18        30
6                17          5

Thanks in advance.
Avatar of QuinnDex
QuinnDex

do you have a timestamp column, if not add one and query against max(timestamp) for each IdProfile
SELECT Last(Profiles.IDMain) AS LastOfIDMain, Profiles.IDProfile, Last(Profiles.Qty) AS LastOfQty
FROM Profiles
GROUP BY Profiles.IDProfile

LastOfIDMain      IDProfile      LastOfQty
     6                          17             5
     4                          18           30

I don't use MySQL, so I am not sure if this syntax would work in MySQL.
ASKER CERTIFIED SOLUTION
Avatar of Amar Bardoliwala
Amar Bardoliwala
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dimensionav

ASKER

Guys, this is a new situation based on this question, maybe you could be interested:
https://www.experts-exchange.com/questions/28325810/How-to-get-previous-record-before-the-last-one.html