SQL Join Question

I have a table1:

1/101/My Test
2/102/Test 2

in table 2

I want now, from table 1 and 2 together
case_id/description/<last state/highest id of case_id from table 2>
101/My Test/3/2

How to make the join for the result? And finally for all case_ids from table 1?
Ingo FoersterProgrammerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun KlineLead Software EngineerCommented:
Maybe something like this:

SELECT table1.case_id, table1.description, table2.id2, table2.state
FROM table1
	INNER JOIN table2 ON table1.case_id = table2.case_id
	INNER JOIN (SELECT case_id, MAX(id2) maxID FROM table2) data
		ON table2.case_id = data.case_id AND table2.id2 = data.maxID

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ingo FoersterProgrammerAuthor Commented:
Thanks you, this helped very much.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.