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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:43:26+00:00 2026-05-24T15:43:26+00:00

I have some tables which all have a field named created_at , that’s a

  • 0

I have some tables which all have a field named created_at, that’s a timestamp to represent when the row inserted.

Now I use mybatis 3 as the persistence layer, I found it a little boring when I query something with join.

Look at the simple sql I expected to get all the questions and their answers:

<select id="selectQuestionsWithAnswers">
      select q.*, a.* from questions as q left inner join answers as a
             on q.id=a.id
      order by a.created_at desc
</select>

But I found, since questions and answers both have field created_at, and if I write select q.*, a.*, there are 2 created_at in the result set, and, the second one is ignored. So the answers will have the created_at value as questions, it’s not correct.

To avoid this, I found 2 ways, but both not good:

  1. Modify the field names of each table, make sure they are not same. For example: questions.created_at -> questions.q_created_at, answers.created_at->answers.a_created_at.

    This is not good because there are a lot of such fields as id, name, title, updated_at, it makes the database hard to read and maintain to change these names

  2. Modify the SQL. Change the field names in sql, like:

    select q.id as q_id, q.title as q_title, ..., q.created_at as q_created_at, 
           a.id as a_id, a.content as a_content, ..., a.created_at as a_created_at
    from questions as q left inner join answers as a
           on q.id=a.id
    order by a.created_at desc
    

    This is not good because I need to change every field names in the SQL, it becomes very long and hard to read, and painful to write such SQLs every time.

I’m new to mybatis, is there any better solution for this problem?

  • 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-24T15:43:28+00:00Added an answer on May 24, 2026 at 3:43 pm

    What about

    <select id="selectQuestionsWithAnswers">
          select q.*, a.*, q.created_at as qtime, a.created_at as atime from questions as q left inner join answers as a
                 on q.id=a.id
          order by atime desc
    </select>
    

    now you’ll have your times in atime and qtime

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

Sidebar

Related Questions

I have a database table which records all field changes in all database tables
I have two tables which have some transactional stuff stored in them. There will
I'm looking at building a Rails application which will have some pretty large tables
Ok, I have a table which contains multiple rows. Each row contains some data
I have a table in database that is having some fields one of which
I have a data table which already has some values, plus it is getting
I have an access table which has some cells as blank ( no data
I have have some code which adds new cells to a table and fills
I have a repeater control outputting some HTML. I want a table which outputs
I have a table on which I want to perform some operations every hour.

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.