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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:18:03+00:00 2026-06-11T04:18:03+00:00

I have a query that I have simplified and written below. How do I

  • 0

I have a query that I have simplified and written below.
How do I display the time difference of 2 fields that were calculated as 2 separate inline select statements?

SELECT x.name ,
   ( SELECT data.ts 
     FROM data 
     WHERE prim_key = x.prim_key and roll_no ='1'  
 ) **starttime** ,
  ( SELECT data.ts 
    FROM woman_data 
    WHERE prim_key = x.prim_key and roll_no ='10'

) **endtime**
, **TIME_TO_SEC( TIMEDIFF( endtime , starttime)** as timediff // This line does not work.It cannot recognize endtime ans starttime
FROM data x 
     INNER JOIN  y 
ON x.prim_key = y.prim_key
ORDER BY x.prim_key
  • 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-11T04:18:05+00:00Added an answer on June 11, 2026 at 4:18 am

    try this:

    starttime and endtime are derived columns, you cannot use it in the same select statement..
    You have to create a derived table then use these columns the a query outside

    select name,starttime,endtime,TIME_TO_SEC( TIMEDIFF( endtime , starttime) as timediff
    from(
    SELECT x.name ,
       ( SELECT data.ts 
         FROM data 
         WHERE prim_key = x.prim_key and roll_no ='1'  
     ) starttime ,
      ( SELECT data.ts 
        FROM woman_data 
        WHERE prim_key = x.prim_key and roll_no ='10'
    
    ) endtime
    
    FROM data x 
         INNER JOIN  y 
    ON x.prim_key = y.prim_key)a
    ORDER BY x.prim_key
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have below a working query that needs to be simplified. The reason is
Below is a simplified version of a query that I have already created. The
I have a query that uses the IN clause. Here's a simplified version: SELECT
I have have this query that i want to execute. SELECT warehouse.expiry_date, pharmacy.expiry_date, drugs.active_substance,
I have a query that looks like this SELECT * from myTable WHERE Date
I have a following query (simplified): SELECT Id FROM dbo.Entity WHERE 1 = ALL
I have a query with a sub query in the select that needs to
Guys, I have a query where basically select the latest browser that our user
I have following (simplified) query: SELECT ResolvedBy, COUNT(*) AS Count, fiCategory, fiSubCategory, fiSymptom FROM
I have a query that I have simplified for our purpose. How do you

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.