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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:45:32+00:00 2026-06-03T09:45:32+00:00

I have a table in mysql, let’s call it foo and it has a

  • 0

I have a table in mysql, let’s call it foo and it has a limitied amount of columns.

| id | name |    date    |
--------------------------
| 1  | bar  | 2012-05-08 |
| 2  | buba | 2012-05-09 |

My users can add records to the table foo_field (stuff like, code, description, time…).

| id | name        |
--------------------
| 1  | code        |
| 2  | description |
| 3  | time        |

In the table foo_field_value the values for the user-defined fields are stored, like so:

| id | foo_id | foo_field_id | value     |
------------------------------------------
| 1  | 1      | 1            | b         |
| 2  | 1      | 2            | Lalalala  |
| 3  | 1      | 3            | 12:00     |
| 1  | 2      | 1            | c         |
| 2  | 2      | 2            | We are go |
| 3  | 2      | 3            | 14:00     |

Ideally, I’d want one query which would give me a result like

| id | name | date       | code | description | time  |
------------------------------------------------------
| 1  | bar  | 2012-05-08 | b    | Lalalala    | 12:00 |
| 2  | buba | 2012-05-09 | c    | We are go   | 14:00 |

Is this even possible without doing an inner join on the foo_fields_value table for every foo_field (generating the query with PHP by doing another query first).

  • 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-03T09:45:33+00:00Added an answer on June 3, 2026 at 9:45 am

    It’s possible to do it in just one, and quite simple.

    We are going to modify the foo_field table a bit, adding a column corresponding to the foo table’s id column, which I assume is the primary key.

    so now we have

    * foo
    |------|
    | id   |
    | name |
    | date |
    |------|
    
    * foo_field
    |-------------|
    | foo_id      |
    | code        |
    | description |
    | time        |
    |-------------|
    

    Which means we can add the extra fields with one simple query:

    SELECT * FROM foo
    LEFT JOIN foo_field ON foo.id = foo_field.foo_id
    

    Which will give us a result set of

    | id | name  |       date | foo_id | code   | description |     time |
    |----+-------+------------+--------+--------+-------------+----------|
    |  1 | asdw  | 2012-05-16 |      1 | asdasd | asdasd      | 15:03:41 |
    |  2 | fdgfe | 2012-05-18 |      2 | asdas  | asdas       | 15:03:41 |
    |  3 | asdw  | 2012-05-16 |      3 | asdas  | asdas       | 15:03:52 |
    |  4 | fdgfe | 2012-05-18 |      4 | asdasd | asdasd      | 15:03:52 |
    

    I am still not sure I surely understood your question. If you want to create truly dynamic values and datastructures, I suggest you save a serialized array into a TEXT field in your database, but I also suggest you to overlook your solution if this is the case; if you want your solution to be able to grow, you want to manage as strict structures as possible.

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

Sidebar

Related Questions

I have a MySQL table. Let's call it Widgets. The Widget table has 3
Let's say I have a mysql table, called foo with a foreign key option_id
Let's say I have a MySQL table and a table has a row with
i have the following mysql table.... ----------------------- id customer_name date ----------------------- now let me
Let's assume that I have a table in a mysql database as follows, date
Let's set the stage, PHP & MYSQL: I have a table we'll call Directions
Let's say I have a MySQL table that is something like this: software table:
I have mysql table that has a column that stores xml as a string.
I have a table in MySQL That looks like the following: date |storenum |views
I have a table in mysql like this Name Result T1_09_03_2010 fail T2_09_03_2010 pass

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.