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

  • Home
  • SEARCH
  • 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 6539271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:50:19+00:00 2026-05-25T10:50:19+00:00

HI I am looking for some help I just can’t seem to get my

  • 0

HI
I am looking for some help I just can’t seem to get my head how self joins work. I have this sql code

select Persno'Name',convert(char(20), A_Date , 13)'Logins',acode 
from atrail as LOGIN 
where acode = 'LOGIN' OR acode = 'LOGOUT'
order by a_date desc

Which produces a list of User names and when the have logged in and out. What I am trying to acheive is to get anther column with the LOGOUT date next to the date they logged in date so that it is easyer to see when they logged in and out.

Thanks

Andy

  • 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-25T10:50:20+00:00Added an answer on May 25, 2026 at 10:50 am

    This could be another way to achieve it:

    SELECT Name, [LOGIN] as login_date, [LOGOUT] as logout_date
    FROM
    (
        SELECT Persno Name,convert(char(20), A_Date , 13) Logins, acode
        FROM atrail 
        WHERE acode = 'LOGIN' OR acode = 'LOGOUT'
        ORDER BY a_date DESC
    ) AS login_table
    PIVOT
    (
        MAX(Logins) FOR acode IN ([LOGIN],[LOGOUT])
    ) AS pvt_table
    ORDER BY login_date DESC
    

    This is considering that for each login date there is a logout date, and that for each person there is just one login and one logout row.

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

Sidebar

Related Questions

I have posted this a few times looking for some help, I cant seem
I am looking for some help. I have found this script that sort of
Looking for some really quick help, contactForm={ that: this, lilfield: 'I just equal this',
looking for some help with images referenced within the stylesheet. I have no problems
-Hello, looking for some help. We currently have a winform app used to do
I've spent some time researching this and still can't figure it out. It seem
Looking for some help and advice please from Super Guru MySQL/PHP pros who can
Would really appreciate some help with this. I have an app which consists of
I am looking for some help with grep, or grep like tools. This includes
I'm sure this is a common problem, but I just can't seem to find

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.