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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:00:55+00:00 2026-06-14T04:00:55+00:00

I have two tables in a database, like so (simplified for question purposes): I

  • 0

I have two tables in a database, like so (simplified for question purposes):

the two tables I have

I don’t want to modify the existing tables or create a new one, but I would like to put all of this data into a consolidated object in my code like so:

the data I want

There are actually more properties in TABLE2 but I am only interested in food and color.

I’m completely new to databases so bear with me – is there a simple way to do this? What I’m thinking so far is doing

SELECT * FROM TABLE1

SELECT PROPERTY_VALUE, UNIQUE_IDENTIFIER 
FROM TABLE2 
WHERE PROPERTY_NAME = 'Favorite Color'

SELECT PROPERTY_VALUE, UNIQUE IDENTIFIER 
FROM TABLE2 
WHERE PROPERTY_NAME = 'Favorite Food'

and then putting them together somehow… Is there a better way? Or if not, where do I go from here?

  • 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-14T04:00:56+00:00Added an answer on June 14, 2026 at 4:00 am

    There are a couple ways to do this, but regardless of which one you use, you generally need to know the number and names of the columns in the result set at the time you write the query. I can give you Favorite Food and Favorite Color, but if there’s any other properties in that table you won’t see them. There is no way to automate that with vanilla sql; you must use dynamic sql or a client-side language if you want to get arbitrary properties from that kind of schema.

    With that constraint out of the way, let’s look at one way you could do this:

    SELECT m.unique, m.last_name, m.first_Name, s1.property_Value As Favorite_Food, s2.property_Value As Favorite_Color
    FROM Table_1 m
    LEFT JOIN Table_2 s1 ON s1.unique = m.unique and s1.property_Name = 'Favorite Food'
    LEFT JOIN Table_2 s2 ON s2.unique = m.unique and s2.property_Name = 'Favorite Color'
    

    Another option is to use the PIVOT keyword, but until we know more details of your actual data, the join above is sufficient.

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

Sidebar

Related Questions

I have a MySQL database with two tables (simplified for this question): movies table
I have two tables in my database which have a one-to-one relationship. I want
I have two tables in my database that look like this CREATE TABLE IF
I have two database tables with some demo data like shown below Create table
I have two tables in my database that look like that: Customer: C_ID city
I have two tables in my MySQL database, one is a library of all
I have two tables in a teradata database that look like this accounts account_number
I have two tables in my database: test1 which looks like: ID pubmed_ID -------------------
I have two database tables, one for Users of a web site, containing the
I have two tables in my database, and I would like to retrieve information

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.