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

  • Home
  • SEARCH
  • 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 7583515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:41:50+00:00 2026-05-30T18:41:50+00:00

Essentially I have some user generated meta data for individual items. Meta data consists

  • 0

Essentially I have some user generated meta data for individual items. Meta data consists of a title and a corresponding value. One item may have one particular metadata title while another may not. So, creating a new collumn in my main table seems like the wrong approach, since I don’t want every item to have the same meta data titles.

The problem is when I want to sort by that meta data. I can easily generate a table that makes the metadata look like just another collumn, but I want to sort by that to. So, to illustrate what I have:

Say I have the following tables:

Items Table:
id | color
----------
0  | red
1  | pink
2  | orange

MetaData Table
itemId |     title     |     data
-----------------------------------------
   0        shape           round
   1   |    shape      |    square
   0   |    sound      |    LOUD!

I can easily write the SQL and code to generate something like the following from those tables:

id  |    color   |   shape    |   sound
--------------------------------------------
0   |    red     |   round    |   LOUD!
1   |    pink    |   square   |            
2   |   orange   |            |   

So, when generating that, if a item doesn’t have a metadata title I’m displaying, then it’s just left blank. I would like to allow the user to sort by shape or sound and just have the ones that are blank show up at the bottom.

I could bring in all the data, generate the tables, then sort it in code..but…that wouldn’t be practical at all for hundreds of entries that I may need to work with.

Is this possible to do in SQL (I’m using mysql, but something more generic would be better in case I change that)? Is my table layout just impractical for this/should I do it a different way (I’d prefer not to change my table layout).

Thanks!

  • 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-30T18:41:51+00:00Added an answer on May 30, 2026 at 6:41 pm

    You can put the blank values at the bottom with something like this:

    select
      Items.id,
      Items.color,
      max(case when title = 'shape' then data else null end) as shape,
      max(case when title = 'sound' then data else null end) as sound
    from Items left outer join MetaData
    on Items.id = MetaData.itemId
    group by Items.id, Items.color
    order by
      case when shape is not null then 0 else 1 end,
      shape
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a List generated from JSON data in Sencha Touch. Essentially, the list
I have a simple class that essentially just holds some values. I have overridden
So I have what is essentially a spreadsheet in TIFF format. There is some
I have what is essentially a jagged array of name value pairs - i
I have a user control with a WebDateTimeEdit server control on it (essentially a
Having some fun with MySQL by asking it difficult questions. Essentially i have a
If you have to use String.Replace() to replace test 50 times, you essentially have
Essentially I have a method of a class called killProgram, which is intended to
I have essentially a survey that is shown, and people answer questions a lot
I have essentially the same problem discussed here: http://khason.net/blog/dependency-property-getters-and-setters-in-multithreaded-environment/ public static readonly DependencyProperty MyPropertyProperty

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.