Answer the question
In order to leave comments, you need to log in
How to search by subgroup?
Good evening.
There is a certain table that stores computer configurations (id, inv_number, date, proc, memory, ...). When changing the configuration, a new line is added, which is guaranteed to match the entry about the previous version of the config only by the inv_number field (the rest may change). It is necessary to compile a list of current equipment (ie records with the latest dates)
Knowledge of sql is not very much, but there are 2 thoughts. The first is to use a subquery
select *
from pc pc1
where pc1.date = (select max(date) from pc pc2 where pc1.inv_number = pc2.inv_number)
Answer the question
In order to leave comments, you need to log in
Not always a working option:
Always working option:
SELECT g.* from pc g
INNER JOIN (
SELECT inv_number, MAX(date) as date FROM pc
GROUP BY inv_number)
AS s USING (inv_number, date)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question