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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:23:42+00:00 2026-05-22T16:23:42+00:00

I am using the following statement to fill an Excel spreadsheet with student information,

  • 0

I am using the following statement to fill an Excel spreadsheet with student information, including “actualstudenthours.”

The problem is, I want to show all students for which the tblstudentstatus.id = 3, but I also need to show actual student hours for those students. Unfortunately, not all of the students have a corresponding entry in “viewactualstudenthours.” This statement completely leaves out those students for which there is no corresponding entry in “viewatualstudenthours.”

How do I get all the students to show up where the tblstudentstatus.id = 3?

If there is no entry for them in viewactualstudenthours, it should not omit the student entirely…the student hours fields should just be blank. Your help would be greatly appreciated.

$result=mysqli_query($dbc,"SELECT tblstudent.first, tblstudent.last,
            LEFT(viewactualstudenthours.ACTUAL_remain,5),
            (SELECT first from tbladdress where tbladdress.id = tblstudent.contact2),
            (SELECT last  from tbladdress where tbladdress.id = tblstudent.contact2),
            tbladdress.address1,tbladdress.city,tbladdress.state,tbladdress.zip1,
            tbladdress.phone, tbladdress.cell, tbladdress.email
            FROM tblstudent, tbladdress, tblstudentstatus, viewactualstudenthours
            WHERE viewactualstudenthours.student_id = tblstudent.id
              AND tblstudent.status = tblstudentstatus.id
              AND tbladdress.id = tblstudent.contact1
              AND tblstudentstatus.id = 3");

(Note: the editor made the SQL semi-legible – but probably broke every rule in the PHP code book.)

  • 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-22T16:23:43+00:00Added an answer on May 22, 2026 at 4:23 pm

    Learn to use the explicit join notation introduced in SQL-92 instead of the older comma-separated list of table names in the FROM clause.

    You need to use a LEFT OUTER JOIN of the table tblstudent with the view viewactualstudenthours. Ignoring the quotes etc needed to make the code work in PHP, you need:

    SELECT S.first, S.last,
           H.ACTUAL_remain,
           A2.first, A2.last,
           A1.address1, A1.city, A1.state, A1.zip1,
           A1.phone,    A1.cell, A1.email
      FROM tblstudent                  AS S
      JOIN tbladdress                  AS A1 ON S.Contact1 = A1.ID
      JOIN tbladdress                  AS A2 ON S.Contact2 = A2.ID
      JOIN tblstudentstatus            AS T  ON S.Status   = T.ID
      LEFT JOIN viewactualstudenthours AS H  ON S.ID       = H.Student_ID
     WHERE T.id = 3
    

    Also learn to use table aliases (the AS clauses) – it simplifies and clarifies the SQL. And if the schema is up to you, don’t prefix the table names with ‘tbl’ and the view names with ‘view’ – it is just so much clutter.

    Note that I got rid of the sub-selects in the select-list by joining to the Address table twice, with two separate aliases. I removed the function LEFT(); you can reintroduce it if you need to.

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

Sidebar

Related Questions

I have following LINQ statement and I want to rewrite it using extension methods.
I'm using the following statement in Java: Arrays.fill(mynewArray, oldArray.Length, size, -1); Please suggest the
How to write following statement in c using switch statement in c int i
in the python console the following statement works perfectly fine (i guess using eval
I came up with the following options: Using the goto statement: Start: goto Data
I am generating a GUID using the following statement in my code byte[ ]
I have created an sqlite table using the following statement: CREATE TABLE IF NOT
I used following code to dynamically fill DropDown controls using AJAX. Each time a
I am using the following statement to load data from a file into a
I'm using the following statement, but not sure how to get the $variables inside

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.