Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8943385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:45:18+00:00 2026-06-15T11:45:18+00:00

apologies for vague question title but not sure on correct wording, please correct if

  • 0

apologies for vague question title but not sure on correct wording, please correct if need be.

I have the following MySQL query which joins several of my tables together.

select distinct(o.person), 
    o.job,
    p.risk,
    r.training,
    case when c.datecompleted  is null then 'no' else 'yes' end TrainingCompleted,
    case when c.expirydate is null then '' else c.expirydate end expirydate
from 
    orgstructure o 
    join personrisks p on p.Person=o.person
    right outer join risktraining r on r.risk=p.risk
    left outer join coursescompleted c on c.course=r.training and c.person=o.person
where o.department='house keeping' and o.person <> ''
order by o.person desc

it produces the below result:

enter image description here

in the result, you can see that each risk has two training solutions that address the risk. I want to return another column status that looks to each training and training completed field, if either of the training is completed then status good else status bad. so my output will only have two rows in this example for each risk. should none of the training have been completed then show any training value as being needed.

ideal output:

enter image description here

How do I edit this query to achieve the desired results.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:45:20+00:00Added an answer on June 15, 2026 at 11:45 am

    easiest way to do it is

    select 
        o.person,
        o.job,
        p.risk,
        case when count(c.datecompleted) > 0 then null else r.training end as training,
        case when count(c.datecompleted) > 0 then 'yes' else 'no' end as TrainingCompleted,
        case when count(c.datecompleted) > 0 then 'good' else 'bad' end as Status
    from orgstructure o 
        join personrisks p on p.Person=o.person
        right outer join risktraining r on r.risk=p.risk
        left outer join coursescompleted c on c.course=r.training and c.person=o.person
    where o.department='house keeping' and o.person <> ''
    group by o.person
    order by o.person desc, case when c.datecompleted is not null then 0 else 1 end asc
    

    Here I do not showing training if either of traning is completed.

    SQL FIDDLE EXAMPLE

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies if the title is vague, but it's not the easiest question to describe.
First the apologies, i'm not sure if my question title even accuratly explains what
Firstly, apologies for the bad question title - not entirely sure if I am
Apologies for the vague question. Here it is: I have a table object created
Apologies for the vague title, but this is quite a difficult problem to explain
Apologies for the poor question title. I have two tables, jobs and Persons-Jobs. Jobs
This is a very wide-ranging/vague question, but here goes. Apologies in advance. The app
Apologies for the vague title of my question. I'm just trying to figure out
Apologies if this question has already been asked but I do not think I
First, I wish to apologize if the title is vague, the question is hard

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.