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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:14:06+00:00 2026-05-28T14:14:06+00:00

I have a table where a plugin keeps all form submissions, in this table

  • 0

I have a table where a plugin keeps all form submissions, in this table I have a row for each field like this:

1 'Name' 'Tony'
2 'Surname' 'Smith'
3 'Mail' 'tony@mail.com'
4 etc.

I want to take all this data to a table where all data is in columns, like this:

New_Id Name   Surname  Mail
     1 'Tony' 'Smith'  'tony@mail.com'
     2 'Mary' 'DotCom' 'mary@dotcom'

I have a A LOT of these records so efficiency is important. My first approach would be a PHP loop on every field in first table and then decide if I have to insert or update in the second table, this solution might even need a previous select to see if field is already populated so the solution is not very nice.

Can you think of a better solution?

EDIT: This is my structure:

This is my target table, field names are in Spanish but they are name, birth_date, adress, etc.

create table target_table
    (id     int not null AUTO_INCREMENT,
    blog_id     int,
    submission_id   int,
    form_id     varchar(250) character set utf8 collate utf8_general_ci,
    submission_date timestamp,
    ip      varchar(250) character set utf8 collate utf8_general_ci,
    sitio           varchar(250) character set utf8 collate utf8_general_ci,
    nombre      varchar(4000) character set utf8 collate utf8_general_ci,
    fecha_nacimiento varchar(250),
    email           varchar(250) character set utf8 collate utf8_general_ci,
    direccion       varchar(250) character set utf8 collate utf8_general_ci,
    cp          varchar(250) character set utf8 collate utf8_general_ci,
    PRIMARY KEY(id));

And source are actually two tables, cforms_submissions is parent with submission_id, submission_date and email:

id               int(11) unsigned PK
form_id          varchar(3)
sub_date         timestamp
email            varchar(40)
ip               varchar(15)

And cforms_data is child table with fields and their values:

f_id             int(11) unsigned PK
sub_id           int(11) unsigned <---- This is FK to parent
field_name       varchar(100)
field_val        text

So, I should do something like:

select submissions....
for each submission
    select fields in submissions
    for each field in submission
        if first_field
            insert
        else
            update

Maybe is there a better approach?

Thank you, BTW, I’m working with MySql

  • 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-28T14:14:07+00:00Added an answer on May 28, 2026 at 2:14 pm

    Sorry, I had misunderstood the question.
    As long as the number of tables if finite you can do N joins in the following way:

    INSERT_INTO target_table(blog_id, form_id, ....) 
    SELECT id, ..., name_table.field_val, address_table, ... 
    FROM cforms_data name_table INNER JOIN cforms_data address_table 
        ON  name_table.sub_id = address_table.sub_id 
        INNER JOIN cforms_data date_table ON name_table.sub_id = name_table.sub_id
        INNER JOIN ...
    WHERE name_table.field_name = 'NAME' AND address_table.field_name = 'ADDRESS' AND...
    

    What you are doing is for each field in the target getting the subset of entries that match that field in the source, and for those matching it with the field in the other subsets with the same ID.
    The query is going to be painfully long since you’ll have an alias per field, but the performance shouldn’t be terrible on if it is properly indexed (probably on field_name,sub_id). I think you can add the field_name comparison in the form, but I am not sure if that is MySQL or only Oracle.
    You probably need the parent for the email, but I that is trivial

    ORIGINAL:

    Just execute in MySql

    INSERT INTO target_table(blog_id, form_id….) SELECT id, form_id,,
    …., … FROM cforms_submissions INNER JOIN cforms_data ON id ==
    sub_id HAVING MAX(sub_date)

    I am assuming you want to insert the last record. Otherwise, vary the SELECT accordingly. The fields in the INSERT INTO have to match the ones in the SELECT.

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

Sidebar

Related Questions

I have table with 50 entries (users with such details like Name Surname Location
I have a table that looks like this: <table name=exercises id=workout-table> <tr> <th>Name</th> <th>Reps/Intervals</th>
I have a table like this I'd like to sort : | Name |
the jquery plugin that im using is this http://code.google.com/p/jquery-in-place-editor/ if i have a table
I have a table of products. In each row is a checkbox to include
I'm using dwilkie's foreigner plugin for rails. I have a table creation statement that
I have table with some fields that the value will be 1 0. This
I have table in data base name train delay, with columns train number(int), DelayTime(int),
I have a table with prices in this format: 1.234,56, (the thousands separator is
I have a table that shows a list of events, each event also has

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.