locked
Nested Select Statement MySQL Query RRS feed

  • Question

  • User1766347310 posted

    Hey everyone, I need help creating a nested Select statement in MySQL.  Currently I have a query that uses a couple inner joins to return a result set.  The query and results are as follows;

    SELECT DISTINCT NoAdmit.InquiryID_fk, Patient.Name, Inquiry.DecisionMade, Inquiry.Date, Inquirer.Name, Inquirer.Program from Patient        INNER JOIN (Inquiry INNER JOIN NoAdmit on NoAdmit.InquiryID_fk = Inquiry.ID Inner Join Inquirer on Inquirer.ID = Inquiry.InquirerID_fk) on    Inquiry.PatientID_fk = Patient.ID
    InquiryID_FK     Name      DecisionMade     Date               Name            Program
    1               Nick         Do Not Admit      1/2/2012       John Doe        Program1

    Since this query is used in an SQLDataSource I would like to append to it to also include this query;

    SELECT * from DecAdmit Where DecAdmit.ActualAdmitDate > GetDate()
    Basically saying, that if the ActualAdmitDate field has a date value that is later than todays date that include that in the resultset. I am just unable how to add this as a nested Select statement or another Join.

    The join could be used on Inquiry.ID = DecAdmit.InquiryID_fk

    Any help would be appreciated.

    Thank you,

    Nick

    Friday, March 9, 2012 10:35 AM

Answers

  • User269602965 posted
    SELECT DISTINCT 
      NoAdmit.InquiryID_fk, 
      Patient.Name, 
      Inquiry.DecisionMade, 
      Inquiry.Date, 
      Inquirer.Name, 
      Inquirer.Program 
    FROM 
      Patient 
    INNER JOIN Inquiry  ON Inquiry.PatientID_fk = Patient.ID
    INNER JOIN NoAdmit  ON NoAdmit.InquiryID_fk = Inquiry.ID 
    INNER JOIN Inquirer ON Inquirer.ID          = Inquiry.InquirerID_fk)
    /
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 9, 2012 2:12 PM