Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hecate0211's avatar

How to select data in table

i have 2 table in my DB, job and job_detail job table have id, name and job_detail have id, job_id(fk), progress

i try this query

select *
from job j INNER JOIN job_detail jd on (j.id=jd.job_id)

and my query result like this

id  name    progress
1   A       20
2   B       2
2   B       40

i just want to get only like this

id  name    progress
1   A       20
2   B       40

can someone help me with this problem?? thx

0 likes
5 replies
tykus's avatar

What is the criteria where 40 is the preferred result for B?

tykus's avatar
tykus
Best Answer
Level 104
SELECT j.id, j.name, jd.progress 
FROM jobs j
INNER JOIN (
    SELECT job_id, max(progress) AS progress
        FROM job_details
        GROUP BY job_id
) AS jd ON j.id = jd.job_id;
hecate0211's avatar

@tykuss can u help me again, i was wrong the critreai wasn't the biggest progress but the lastest date..

Please or to participate in this conversation.