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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:04:43+00:00 2026-05-30T08:04:43+00:00

I have this database structure: sites id | name 1 | Site 1 2

  • 0

I have this database structure:

sites
id | name
1  | Site 1
2  | Site 2

locations
id | city
23 | Baltimore
24 | Annapolis

people
id | name
45 | John
46 | Sue

sites_meta
id | site_id | meta_name | meta_value
1  |    1    |   local   |     23
2  |    1    |   person  |     45
3  |    2    |   local   |     24
4  |    2    |   person  |     46

So, as you can see, Site 1 (id 1) is in Baltimore and is associated with John, Site 2 (id 2) is in Annapolis and associated with Sue.

I need to figure out a clever sql statement that can return

id |   name   | id |    city    | id | name
 1 |  Site 1  | 23 |  Baltimore | 45 | John
 2 |  Site 2  | 24 |  Annapolis | 46 | Sue

I would be super appreciative if anyone can help me out. I’ve tried a few combinations of a select statement, but I keep getting stuck with using two values from the sites_meta table.

  • 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-30T08:04:45+00:00Added an answer on May 30, 2026 at 8:04 am
    select
        s.id as siteId,
        s.name as siteName,
        max(l.id) as locationId,
        max(l.city) as city,
        max(p.id) as personId,
        max(p.name) as personName
    from
        sites_meta sm
        join sites s on s.id = sm.site_id
        left join locations l on l.id = sm.meta_value and sm.meta_name = 'local'
        left join people p on p.id = sm.meta_value and sm.meta_name = 'person'
    group by
        s.id,
        s.name
    

    You can probably imagine how this kind of “meta” table might become a pain… especially as more items are added to it.

    Instead, you might consider replacing it with two new tables, sites_locations and sites_people.

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

Sidebar

Related Questions

I have created a table on an Oracle 10g database with this structure :
In mysql database i have this column called: Name: Date Type: datetime I have
I have this legacy database for which I'm building a custom viewer using Linq
I have this scenario where I need data integrity in the physical database. For
I have this algorithm in Java to store passwords in database. I'd like to
I have this function on my controller (Im using CodeIgniter) that reads the database,
I have this question in which I have a SQL Server Compact Edition database
I have a database on a SQL Server 2000 server. This database has a
I have a production database where usage statistics reside. This database is responsible for
I have a requirement to implement contact database. This contact database is special in

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.