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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:56:00+00:00 2026-06-18T03:56:00+00:00

I have a table that is populated with data from a query that selects

  • 0

I have a table that is populated with data from a query that selects studentid numbers from a database. the view is like so :

Pic

As you can see the same piece of data is being output multiple times. I have a feature that for any reason a counselor can not finish a student then they can send the student to another counselor. Now to maintain historic data I keep all that data. Now when I go back to my student que then it shows all the current data (which I want) and all the past historic data (which I dont want)

this is my sql statement :

    try 
                {
            $query = $dbh->prepare("SELECT 
        session.session_id AS id, 
        session.anum, 
        student.first, 
        student.last, 
        session.why, 
        session.studentcomments, 
        session.aidyear,
        support.counselorcomments 
        FROM 
        student INNER JOIN session ON student.anum = session.anum 
        INNER JOIN session_status ON session.status = session_status.status 
        LEFT JOIN support ON session.session_id = support.session_id
        WHERE session.status = 0 OR session.status = 2");

    $query->execute();
            $result = $query->fetchall();
                }
                    catch (PDOException $e) {
                    error_log($e->getMessage());
                    die($e->getMessage());
}

Now the way I have my database set up is how I want to keep it as it works. I just think the way I am querying the data is what the problem is.

this is a picture of the data in mysql :

enter image description here

EDIT

Now since that problem is fixed now I am having an error that when ever a insert happens (updating the support.starttime timestamp) the above record disappears this is my updated sql

$query = $dbh->prepare("SELECT session.session_id AS id, session.anum, student.first, student.last, session.why, 
                        session.studentcomments, session.aidyear, support.counselorcomments FROM student LEFT JOIN 
                        session ON student.anum = session.anum LEFT JOIN session_status ON 
                        session.status = session_status.status LEFT JOIN support ON session.session_id = support.session_id
                        WHERE (session.status) IN (0) OR (session.status) IN (2) 
                        AND support.starttime = (SELECT MAX(support.starttime) FROM support INNER JOIN session ON session.session_id = 
                        support.session_id)");
  • 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-18T03:56:02+00:00Added an answer on June 18, 2026 at 3:56 am
    SELECT DISTINCT 
        session.session_id as id,
        session.anum,
        student.first,
        student.last,
        session.why,
        session.studentcomments,
        session.aidyear,
        support.counselorcomments
    FROM student
            INNER JOIN session 
                ON student.anum = session.anum
            LEFT JOIN support 
                ON session.session_id = support.session_id
            WHERE session.status IN (0,2)
    

    Used DISTINCT as ALberto told me to do! Thank you alberto

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

Sidebar

Related Questions

I have a large table that get populated from a view. This is done
I have table that I insert data with following query (from c# code): INSERT
I have a table Survey_Data_Response that is populated with an 'insert into' statement from
I have a working mysql query that retrieves data from table1. Now I will
I'm making a query that pulls a lot of data from a sql table.
I have a code that populates data from a mysql table into an html
I have a table that I need to extract data from, and wish to
In a nutshell: I have some database table data that I want to populate
My table is being populated using ajax from a mysql database. I have a
I have two columns in a table that are populated with integer values. For

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.