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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:32:08+00:00 2026-05-31T01:32:08+00:00

I have a view like this one id name characteristic value isList 1 cube

  • 0

I have a view like this one

id     name     characteristic     value     isList
1      cube         sides           6          0
1      cube         color          blue        0
2    triangle       sides           3          0
3    hexagon        (null)        (null)     (null)
4    rectangle      weight          15         0

I need to select all ids and names and retrieve some characteristics and the respective value. for instance, I want to retrieve all figures (ids 1, 2, 3 and 4) and the characteristics sides and color (if are available, if not, only id and name are filled up; the others are null).

I tried

select *
from shapes_view
where (id = 1 or id = 2 or id = 3 or id = 4) and (characteristic like 'sides' or characteristic like 'color')

but it, obviously, retrieves the ids 1 and 2 but not 3 and 4.

My guess is that I need some sort of subquery to do this but when I try to join this view with itself, I get a long list of combinations that aren’t anywhere near of what I need.

What i intend to get is something like

id     name     characteristic     value     isList
1      cube         sides           6          0
1      cube         color          blue        0
2    triangle       sides           3          0
3    hexagon        (null)        (null)     (null)
4    rectangle      (null)        (null)     (null)

I know I can select all values and exclude what I do not what in the java side, but it doesn’t sound very correct…

Can anyone help me on this one?
Best regards

  • 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-31T01:32:09+00:00Added an answer on May 31, 2026 at 1:32 am

    You can use a self join– actually, a couple of self joins

    select all_ids.id,
           all_ids.name,
           s.value sides,
           c.value color
      from shapes_view all_ids
           left outer join (select *
                              from shapes_view
                             where characteristic = 'sides') s
                   on( s.id = all_ids.id )
           left outer join (select *
                              from shapes_view
                             where characteristic = 'color') c
                   on( c.id = all_ids.id )
    

    Or you can pivot the data

    select id,
           name,
           max( case when characteristic = 'sides'
                     then value
                     else null
                  end) sides,
           max( case when characteristic = 'color'
                     then value
                     else null
                  end) color
      from shapes_view
     group by id, name
    

    The complexity of the queries required to extract data for N different attributes is one of the reasons that this sort of very generic entity-attribute-value data model is generally frowned upon.

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

Sidebar

Related Questions

I have a mvc2 application with a view like this <% using (Ajax.BeginForm(UserApprove, new
I have a View that renders something like this: Item 1 and Item 2
I have added a UILabel to my view programmatically like this: myLabel = [[UILabel
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {
I'm having some difficulties with Ajax.BeginForm I have something like this in a view
I have a FrameLayout view which contains one (MapView-like) control and some additional buttons
I have this one in View: <% foreach (var item in (List<MyType>)ViewData[MyTypeArray]) { %><tr>
This one is strange...I have the following markup for a view using Razor view
I have a view like this: info_dict = [{u'Question 1': ['13365', '13344']}, {u'Question 2':
i have view like 'home/details/5', it can be access by anonymous user. but there

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.