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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:05:34+00:00 2026-05-25T16:05:34+00:00

I have two tables. TableA Userid Starttime reason John yyyy-mm-dd hh:mm:ss logged in Table

  • 0

I have two tables.

TableA

    Userid  Starttime               reason
    John    yyyy-mm-dd hh:mm:ss     logged in

Table B

    Userid  Date            Starttime              reason
    John    yyyy-mm-dd    yyyy-mm-dd hh:mm:ss     logged in

I need to update the starttime of table B with min(a.starttime) while a.Userid = b.userid, a.starttime = b.date, and reason = ‘logged in’.

I seem to be having issues with using Min(a.starttime) as what I want to use to update.

My query is below:

update B
set B.starttime = (
  select Min(A.Starttime)
  from table as A
  where B.UserID = A.UserID
  and (CONVERT(DATETIME,A.DATE,102)) = (CONVERT(DATETIME,B.Date,102)))
  and  (A.Reason = 'loggedin')
)
from table2 as B

I convert the dates since table B has the date as for example 2011-09-13 00:00:00 and A has the date and times.

  • 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-25T16:05:35+00:00Added an answer on May 25, 2026 at 4:05 pm

    If you’re just not getting the right results, it may be because you need to use convert(varchar, date, 102) instead of convert(datetime, date, 102). If that doesn’t help, try this.

    Instead of doing the subquery inside the SET portion, use it as a derived table and JOIN to it. Even if the above fixes the results, the below query should be far more efficient.

    update B
    set B.starttime = A.starttime
    from table2 as B
    INNER JOIN (
    select A.UserId, convert(varchar, A.Date, 102) as adate, Min(A.Starttime) as starttime
      from table as A
      WHERE  (A.Reason = 'loggedin')
      GROUP BY A.UserId, convert(varchar, A.Date, 102)
    ) A on B.Nordia_ID = A.UserId and A.adate = convert(varchar, B.StatusDateTime, 102)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables set up in phpmyadmin- table userid and table data. The
I have set up 2 two tables - table userid and table data in
If i have two tables like user table-u userid | name 1 | lenova
Ok, So I have these two tables - BioUser- UserId,Weight,DateAdded DimDate-Date // It has
hope someone can help. I have two tables: Users -UserID -UserName UsersType -UserTypeID -UserID
I have two tables: a 'userlist' that has a 'grade' and 'userID' columns, and
i have two mysql tables tableA colA1 colA2 1 whatever 2 whatever 3 whatever
i have two msaccess tables tableA textA numA bd 1 as 0 aa 2
Say for example, I have the following two tables: TableA { _id } TableB
I have two tables, related by a common key. So TableA has key AID

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.