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 7582199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:22:41+00:00 2026-05-30T18:22:41+00:00

I’m building a database for my work and I’m having trouble figuring out how

  • 0

I’m building a database for my work and I’m having trouble figuring out how to build this query.

The tables relevant to my problem are:

job

Surgical_Planning – has job as foreign key, exists for some jobs, doesn’t for others

Medical_Model – has job as foreign key, 1 to 1 relationship with job

This is a working query where I don’t have any information about the surgical planning

    SELECT
    job,
    physician_idphysician as Physician,
    patient_idpatient as Patient,
    status,
    DATE_FORMAT(scan_date, '%M %e, %Y, %l:%i%p') as Scan_Date,
    DATE_FORMAT(timestamp, '%M %e, %Y, %l:%i%p') as Recieved,
    DATE_FORMAT(date_required, '%M %e, %Y, %l:%i%p') as Date_Required
    FROM
    job, patient_has_physician as phys, Scan, Medical_Model as med
    WHERE
    Scan.job_job = job AND phys.job_job = job
    AND med.job_job = job AND job.type =  'medical

I think I want to do a Left join so that it will display every job in order, with all the information in the query above, but then when there is a Surgical_Planning for a job # I want there to be a column for that as well. Here is my attempt that is not working

    SELECT
    job,
    physician_idphysician as Physician,
    patient_idpatient as Patient,
    status,
    DATE_FORMAT(scan_date, '%M %e, %Y, %l:%i%p') as Scan_Date,
    DATE_FORMAT(timestamp, '%M %e, %Y, %l:%i%p') as Recieved,
    DATE_FORMAT(date_required, '%M %e, %Y, %l:%i%p') as Date_Required
    FROM
    job, patient_has_physician as phys, Scan, Medical_Model as med

    LEFT JOIN Surgical_Planning ON job.job = Surgical_Planning.job_job
    AND Scan.job_job = job AND phys.job_job = job
    AND med.job_job = job AND job.type = 'medical'

I can get this basic left join working the way I want, but if I want to add more columns like above it doesn’t work.

    SELECT job, planning_id
    FROM job
    LEFT JOIN Surgical_Planning ON job = Surgical_Planning.job_job

could a subquery be used as well? I can figure out these more basic queries but really have trouble with these more complex join and subquery ones. any advice is appreciated.

EDIT — Job table schema


— Table mmrl.job


DROP TABLE IF EXISTS mmrl.job ;

CREATE TABLE IF NOT EXISTS mmrl.job (

job INT(11) NOT NULL AUTO_INCREMENT ,

type VARCHAR(45) NULL ,

status VARCHAR(45) NULL DEFAULT NULL ,

timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,

PRIMARY KEY (job) )

ENGINE = InnoDB

DEFAULT CHARACTER SET = latin1;

  • 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-05-30T18:22:43+00:00Added an answer on May 30, 2026 at 6:22 pm

    change

    LEFT JOIN Surgical_Planning ON job.job = Surgical_Planning.job_job
    AND Scan.job_job = job AND phys.job_job = job
    AND med.job_job = job AND job.type = 'medical'
    

    to

    LEFT JOIN Surgical_Planning ON job.job = Surgical_Planning.job_job
    WHERE Scan.job_job = job AND phys.job_job = job
    AND med.job_job = job AND job.type = 'medical'
    

    EDIT:

    the left join occurs against the table to the left of the actual LEFT JOIN syntax. Move job to the end of your from list and try again.

    FROM patient_has_physician as phys, Scan, Medical_Model as med, job
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am currently running into a problem where an element is coming back from

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.