/    Sign up×
Community /Pin to ProfileBookmark

Inconsistent Query Result on left join

I connect two tables **tbl_agro_exploatare** and **tbl_agro_works** to list all the records from tbl_agro_exploatare and MaxDate records from tbl_agro_works. Indeed I succeed to retrieve records with MaxDate but **ID.tbl_agro_work**s value is inconsistent and wrong. **ID** value from **tbl_agro_works** in my list doesnt belong to the row of **MaxDate** which was retrieved with left join.

On the contrary I receive first ID value of the records with same **EXPLOATARE_ID.**

How I can fix the problem?

`SELECT TAE.PARCELA_ID, TAE.CAMPANIA_ID, TAW.MaxDate, TAW.ID AS TAWID FROM tbl_agro_exploatare TAE
LEFT JOIN
(select EXPLOATARE_ID, ID, max(TARIH) as MaxDate from tbl_agro_works
GROUP BY EXPLOATARE_ID) TAW on TAW.EXPLOATARE_ID = TAE.ID`

to post a comment

1 Comments(s)

Copy linkTweet thisAlerts:
@siddhi_patelDec 05.2019 — HI...

``<i>
</i>SELECT tae.id,
taw.MaxDate,
taw.id workid
FROM tbl_agro_exploatare tae
LEFT JOIN ( SELECT MAX(id) id,
exploatare_id,
MAX(tarih) MaxDate
FROM tbl_agro_works
GROUP BY exploatare_id
) taw ON taw.exploatare_id = tae.id
ORDER BY tae.id<i>
</i>
``
×

Success!

Help @deepdelver spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...