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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:39:06+00:00 2026-06-18T11:39:06+00:00

I ran into some problems while structuring my database, and I will ask two

  • 0

I ran into some problems while structuring my database, and I will ask two questions.

First question: below table needs to be merged by the same IDs

 ╔═════╦═══════╦═════╦═══════╗
 ║ id* ║ name  ║ age ║ grade ║
 ╠═════╬═══════╬═════╬═══════╣
 ║  0  ║ John  ║     ║       ║
 ║  0  ║       ║ 11  ║       ║
 ║  0  ║       ║     ║   6   ║
 ║  1  ║ Dave  ║     ║       ║
 ║  1  ║       ║ 12  ║       ║
 ║  1  ║       ║     ║   7   ║
 ╚═════╩═══════╩═════╩═══════╝

so it should look like this;

 ╔═════╦═══════╦═════╦═══════╗
 ║ id* ║ name  ║ age ║ grade ║
 ╠═════╬═══════╬═════╬═══════╣
 ║  0  ║ John  ║ 11  ║   6   ║
 ║  0  ║ Dave  ║ 12  ║   7   ║
 ╚═════╩═══════╩═════╩═══════╝

NOTE: id* is not AUTO_INCREMENT


Second question: You probably think that the former database structure is poor. The good thing is, I haven’t created the database yet and I have been looking for a solution to add data to an existing row without removing old information, but if there is no old information, it would create a new row. Thanks in advance.

Second question explained

Virgin table

 ╔═════╦═══════╦═════╦═══════╗
 ║ id* ║ name  ║ age ║ grade ║
 ╠═════╬═══════╬═════╬═══════╣
 ║     ║       ║     ║       ║
 ╚═════╩═══════╩═════╩═══════╝

some SQL statement

 ╔═════╦═══════╦═════╦═══════╗
 ║ id* ║ name  ║ age ║ grade ║
 ╠═════╬═══════╬═════╬═══════╣
 ║  0  ║ John  ║     ║       ║
 ╚═════╩═══════╩═════╩═══════╝

the same SQL statement with different parameters

 ╔═════╦═══════╦═════╦═══════╗
 ║ id* ║ name  ║ age ║ grade ║
 ╠═════╬═══════╬═════╬═══════╣
 ║  0  ║ John  ║     ║       ║
 ║  1  ║ Dave  ║     ║       ║
 ╚═════╩═══════╩═════╩═══════╝

another SQL statement

 ╔═════╦═══════╦═════╦═══════╗
 ║ id* ║ name  ║ age ║ grade ║
 ╠═════╬═══════╬═════╬═══════╣
 ║  0  ║ John  ║     ║       ║
 ║  1  ║ Dave  ║ 12  ║       ║
 ╚═════╩═══════╩═════╩═══════╝

another SQL statement

 ╔═════╦═══════╦═════╦═══════╗
 ║ id* ║ name  ║ age ║ grade ║
 ╠═════╬═══════╬═════╬═══════╣
 ║  0  ║ John  ║     ║   6   ║
 ║  1  ║ Dave  ║ 12  ║       ║
 ╚═════╩═══════╩═════╩═══════╝

… and so on.

  • 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-18T11:39:07+00:00Added an answer on June 18, 2026 at 11:39 am

    You should be able to apply an aggregate function to all the columns and then GROUP BY id:

    select id,
      max(name) name,
      max(age) age,
      max(grade) grade
    from yourtable
    group by id
    

    See SQL Fiddle with Demo

    As far as the DB structure, the only issue that I see is that you are inserting multiple records for the same user. You should be using an UPDATE statement to use the values instead of inserting.

    It sounds like you want to use the REPLACE function in MySQL (here is a tutorial).

    So the query would be similar to this:

    REPLACE 
      INTO yourtable (`id`, `name`, `age`, `grade`) 
      VALUES (0, 'john', 11, null);
    

    See SQL Fiddle with Demo

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

Sidebar

Related Questions

While creating an online shop application using play-1.2.4 ,I ran into some problems with
Ran into this error message while trying to select some records off a table.
while trying to deploy a Grails application into tomcat6 I ran into some problems:
i'm busy writing my very first jquery plugin and i ran into some problems.
(this is regarding the Ramaze.net framework) I ran into some really strange problems while
Best practices question. While I was writing some event handlers, I ran into an
I decided to play with some CSS3 and ran into some problems with background
I ran into some trouble while creating a C-Extension for ruby that got me
It's been a while since I got into QCL but I ran into some
i'm writing some stuff in java and i ran into some problems lately. cut

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.