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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:26:41+00:00 2026-06-12T14:26:41+00:00

I have a table structure in MySQL where I have the following structure: home_id,

  • 0

I have a table structure in MySQL where I have the following structure:

home_id, home_name, dateadded

I have another table called specs with the following structure:

home_id, spec_key, spec_value

In it I can have entries like the following:

1, price, 500000
1, location, 90210
1, rooms, 3
1, washrooms, 3
1, furnished_basement, 0
2, location, 14410
2, garage_size, 3
2, price, 335000

For search purposes, I’d like to denormalize the above. The table (denormalized_homes) structure would look something like:

home_id, price, location, rooms, washroom, furnished_basement, garage_size, dateadded

As you can see from the above, a) not all entries have a value for all columns. b) The table structure is not conducive to INSERT INTOdenormalized_homesselect * fromspecs type queries. I also can’t used stored procedures or triggers (host regulations).

The tactic I’ve taken so far is to insert home_id into the denormalized_homes table, and then run through each field in spec with something like the following query:

UPDATE `denormalized_homes` dh, specs s SET dh.price = s.spec_value WHERE dh.home_id = s.home_id AND s.spec_key = "price";

Creating a query for each possible column and then running them works. I’m just thinking there must be a better way, is there?

  • 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-12T14:26:43+00:00Added an answer on June 12, 2026 at 2:26 pm

    I think you could do something like this:

    INSERT INTO denormalized_homes ()
    
    SELECT h.home_id,
           price.spec_value price,
           location.spec_value location,
           rooms.spec_value rooms,
           washroom.spec_value washroom,
           furnished_basement.spec_value furnished_basement,
           garage_size.spec_value garage_size,
           h.date_added
    
    FROM   homes h
    
           LEFT JOIN specs price
           ON price.home_id = h.home_id and spec_key = 'price'
    
           LEFT JOIN specs location
           ON price.home_id = h.home_id and spec_key = 'location'       
    
           LEFT JOIN specs rooms
           ON price.home_id = h.home_id and spec_key = 'rooms'
    
           LEFT JOIN specs washroom
           ON price.home_id = h.home_id and spec_key = 'washroom'
    
           LEFT JOIN specs furnished_basement
           ON price.home_id = h.home_id and spec_key = 'furnished_basement'
    
           LEFT JOIN specs garage_size
           ON price.home_id = h.home_id and spec_key = 'garage_size'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following MySQL table structure: num field company phone website 1 Gas
I have the following table structure (in MySQL): DocID, Code, IsDup, DopOf , where
Lets say I have the following MySQL structure: CREATE TABLE `domains` ( `id` INT(10)
I have a MySQL table with a structure like the following: I'm looking for
I have a MySQL database with the following table structure: TransactionType : Transaction_Amount, Transaction_ID,
I have a MySQL tag-mapping table with structure from the following post - Recommended
In MySQL, is it bad to have a table structure like the following... Table
I have following table structure in Mysql DB Table: Mytable -------------------------------- | uid |
I have the following MySQL structure (minimized a lot): CREATE TABLE `site_movies` ( `id`
I have the following table structure in my db (MySQL): id group_id item_id project_id

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.