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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:37:57+00:00 2026-06-12T05:37:57+00:00

I have these two tables: desc students +———————–+———+——+—–+———+—————-+ | Field | Type | Null

  • 0

I have these two tables:

desc students
+-----------------------+---------+------+-----+---------+----------------+
| Field                 | Type    | Null | Key | Default | Extra          |
+-----------------------+---------+------+-----+---------+----------------+
| student_id            | int(11) | NO   | PRI | NULL    | auto_increment |
| student_ticket_number | int(11) | YES  |     | 0       |                |
+-----------------------+---------+------+-----+---------+----------------+

desc studentdates
+-----------------------+---------+------+-----+---------+----------------+
| Field                 | Type    | Null | Key | Default | Extra          |
+-----------------------+---------+------+-----+---------+----------------+
| student_date_id       | int(11) | NO   | PRI | NULL    | auto_increment |
| student_id            | int(11) | YES  |     | NULL    |                |
| student_ticket_number | int(11) | YES  |     | 0       |                |
+-----------------------+---------+------+-----+---------+----------------+

I would like to move the column students.student_ticket_number to studentdates.student_ticket_number where the field student_id match.

So if the user John has student_id = 1 move his ticketnumber (for example 1234) from students.student_ticket_number to studentdates.student_ticket_number WHERE student_id = '1'.

In the table studentdates.student_id there can be multiple identical records then I would like to use the lowest studentdates.student_date_id and skip the others. Tell me if this is unclear.

I guess I need to do a subquery somehow but how?

  • 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-12T05:37:58+00:00Added an answer on June 12, 2026 at 5:37 am

    You need to get the minimum student_date_ID in a subquery then join it with the other tables. try this,

    UPDATE  students a
            INNER JOIN studentdates b
                ON a.student_ID = b.student_ID
            INNER JOIN
            (
                SELECT  student_ID, MIN(student_date_ID) minID
                FROM    studentDates
                GROUP BY student_ID
            ) c ON b.student_ID = c.student_ID AND
                   b.student_date_id = c.minID
    SET     a.student_ticket_number = b.student_ticket_number
    WHERE   a.student_id = '1'
    

    UPDATE  students a
            INNER JOIN studentdates b
                ON a.student_ID = b.student_ID
            INNER JOIN
            (
                SELECT  student_ID, MIN(student_date_ID) minID
                FROM    studentDates
                GROUP BY student_ID
            ) c ON b.student_ID = c.student_ID AND
                   b.student_date_id = c.minID
    SET     b.student_ticket_number = a.student_ticket_number
    WHERE   a.student_id = '1'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables with a single common field. Here is how these two
I have these two tables people ============ id, name and answer_sheets ============ id, person_id,
If I have these two tables: <table> <tr> <td>Small Length Content</td> </tr> </table> <table>
Hi, I have these two tables: users and friends (friend_status = 1 means the
Hi, I have these two tables: users and friends (friend_status = 1 means the
This is SQL Server 2008. I have these two tables and a join: DECLARE
We have two tables Family and Member, the relation between these two is Family
I have tables like these two test_table date student test 2012-05-31 Alice Math 2012-05-31
I have two tables (using table variables for illustration. You can run these directly
I have two tables, tbl_foo and tbl_bar , and I want to join these

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.