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

The Archive Base Latest Questions

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

SELECT session.session_id as ID, session.anum, student.first, student.last, session.why, session.studentcomments, session.aidyear, support.counselorcomments FROM student INNER

  • 0
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
LEFT JOIN support ON session.session_id = support.session_id
LEFT JOIN (
SELECT session_id, cid, starttime FROM support ORDER BY starttime asc limit 1
) 
AS timing ON timing.session_id = session.session_id 
WHERE session.status NOT IN (0,2);

This returns me with this value :

+-----+-----------+---------+---------+--------------+-----------------+---------+-------------------+
| ID  | anum      | first   | last    | why          | studentcomments | aidyear | counselorcomments |
+-----+-----------+---------+---------+--------------+-----------------+---------+-------------------+
| 175 | A00000000 | rixhers | ajazi   | Appeal       |                 | 12-13   | NULL              |
| 176 | B00000000 | Testing | thisout | Tap Question |                 | 12-13   | omg!              |
| 176 | B00000000 | Testing | thisout | Tap Question |                 | 12-13   | Jesus!!           |
+-----+-----------+---------+---------+--------------+-----------------+---------+-------------------+
3 rows in set (0.00 sec)

I do not want to have both ID’s of 176 there, I want the most recently added one (that is why i use order by starttime asc limit 1 on my subquerys). Is there any way I can get this to work with the means that I have set forward now?

Edit Number 1 :

mysql> 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
    ->         LEFT JOIN support 
    ->             ON session.session_id = support.session_id
    ->         LEFT JOIN 
    ->         (
    ->             SELECT session_id, max(starttime) max_time
    ->             FROM support 
    ->             GROUP BY session_id
    ->         ) timing ON timing.session_id = support.session_id AND
    ->                     timing.max_time = support.starttime
    -> WHERE   session.status IN (0,2);
+-----+-----------+---------+---------+--------------+-----------------+---------+-------------------+
| ID  | anum      | first   | last    | why          | studentcomments | aidyear | counselorcomments |
+-----+-----------+---------+---------+--------------+-----------------+---------+-------------------+
| 175 | A00000000 | rixhers | ajazi   | Appeal       |                 | 12-13   | NULL              |
| 176 | B00000000 | Testing | thisout | Tap Question |                 | 12-13   | omg!              |
| 176 | B00000000 | Testing | thisout | Tap Question |                 | 12-13   | Jesus!!           |
+-----+-----------+---------+---------+--------------+-----------------+---------+-------------------+
3 rows in set (0.00 sec)

Did not have the desired effect either anything else? Should my support.starttime be a index the database so timing.starttime = support.starttime will work?

Edit 2 :

mysql> SELECT session_id,
    -> max(starttime) max_time FROM support
    -> GROUP BY session_id;
+------------+---------------------+
| session_id | max_time            |
+------------+---------------------+
|        176 | 2013-01-28 07:44:17 |
+------------+---------------------+
1 row in set (0.00 sec)

Edit 3 :

mysql> SELECT session_id, cid, starttime FROM support;
+------------+-----+---------------------+
| session_id | cid | starttime           |
+------------+-----+---------------------+
|        176 |   1 | 2013-01-28 07:44:08 |
|        176 |   2 | 2013-01-28 07:44:17 |
+------------+-----+---------------------+
2 rows in set (0.00 sec)

EDIT : works now, thank you JQ for trying to help!

and thank you to sgeddes for the answer!

mysql> 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
    ->         LEFT JOIN support support2
    ->             ON support.session_id = support2.session_id
    ->                 AND support.starttime < support2.starttime
    -> WHERE   session.status IN (0,2) 
    ->     AND support2.session_id IS NULL;
+-----+-----------+---------+---------+--------------+-----------------+---------+--------------------+
| id  | anum      | first   | last    | why          | studentcomments | aidyear | counselorcomments  |
+-----+-----------+---------+---------+--------------+-----------------+---------+--------------------+
| 175 | A00000000 | rixhers | ajazi   | Appeal       |                 | 12-13   | yo please help me! |
| 176 | B00000000 | Testing | thisout | Tap Question |                 | 12-13   | Jesus!!            |
| 177 | C00000000 | ufufu   | ufufjn  | Appeal       |                 | 12-13   | NULL               |
+-----+-----------+---------+---------+--------------+-----------------+---------+--------------------+
3 rows in set (0.00 sec)

Edit 4: doesnt change the table, I just have a historic view available for when i am running reports. and then I needed a up to date current view for now.

mysql> SELECT session_id, cid, counselorcomments starttime FROM support;
+------------+-----+-------------------+
| session_id | cid | starttime         |
+------------+-----+-------------------+
|        175 |   4 | NULL              |
|        175 |   5 | help!             |
|        175 |   7 | please need help! |
|        176 |   1 | omg!              |
|        176 |   2 | Jesus!!           |
|        177 |   1 | ihgggwhb          |
+------------+-----+-------------------+
6 rows in set (0.00 sec)
  • 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:01:11+00:00Added an answer on June 18, 2026 at 3:01 am

    Here’s an alternative to using a subquery. You could just join on the table again. Something like this:

    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
            INNER JOIN support 
                ON session.session_id = support.session_id
            LEFT JOIN support support2
                ON support.session_id = support2.session_id
                    AND support.starttime < support2.starttime
    WHERE   session.status NOT IN (0,2) 
        AND support2.session_id IS NULL
    

    Both approaches should produce the same results.

    Good luck.

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

Sidebar

Related Questions

session.createQuery(Select attribute from GoodsSection tgs + join gs.ascendants ags join ags.attributes attribute + where
I want to run the following query :: SELECT S.* FROM sys.dm_exec_requests S JOIN
I have a MySQL query SELECT * FROM 'redirect' WHERE 'user_id'= \''.$_SESSION['user_id'].' \' ORDER
I have an NHibernate query that looks like this: var query = Session.CreateQuery(@ select
I'm able to set variable values for where restrictives: Query criteria = session.createQuery( select
SELECT REPLACE([strUrl], '/myoldurl', '/mynewurl') FROM [UrlRewrite] If strUrl is /myoldurl/myoldurl_something_else , it returns /mynewurl/mynewurl_something_else
SELECT Id,Date,Name FROM people WHERE DATEPART(hh,Date) >= 7 AND DATEPART(hh,Date) <= 8 Order by
select tf.Id,tf.Name,tf.LName,tf.Rank,tf.Category where tf.Id not in (select fighter_id from tbl_player_fighter where league_id=91) and tf.Status
I want to get the details of some attribute(session,trade,student etc.), and i have their
Here is my query: SELECT count(*) FROM table_testcase_execution WHERE campaign_session_id = any(SELECT campaign_session_id 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.