Graham B
Graham B

Reputation: 39

Use of Subquery in a query

I have a mysql database which has a number of tables:

Rules

I want to extract a table which shows all matters where their state is 'Open' and lists the matterid, mattername, the staffname for the person who is the lead on the matter (i.e. has lead='Y') and the last actiondate for the matter.

I have tried various ways of doing this and believe that it can be done using subqueries but I can’t work out the format for getting these into my query.

Upvotes: 0

Views: 52

Answers (1)

WorkSmarter
WorkSmarter

Reputation: 3808

It would look like this:

Select m.matterid, m.mattername, s.staffname, max(actiondate)
From matters m
Inner join matterjuncstaff mjs using (matterid)
Inner join staff s using (staffid)
Inner join matterjunactions mj
 On mj.Matterid = m.matterid
Where m.state = 'open'
And s.lead = 'Y'
Group by m.matterid, m.mattername, s.staffname

Upvotes: 1

Related Questions