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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:02:57+00:00 2026-06-17T11:02:57+00:00

I have a complex data structure I am working with and I am not

  • 0

I have a complex data structure I am working with and I am not quite sure how to tackle it in a single SQL query, although my gut tells me this should be possible to do.

The essence of what I am doing is trying to display the results of available plans for a given vendor based on the selected hardware model. The results should adhere to only possible combinations, and the plans contain restrictions which are currently stored as key/value pairs in a restrictions table. Below is a simplification of what I am working with:

(I will use a wireless device analogy since almost everyone is familair with cell phones)

models Table


model_id
vendor_id
is_data
is_voice
is_4g
is_3g

Sample Data:

model_id,vendor_id,is_data,is_voice,is_4g,is_3g
DeviceA,Sprint,1,1,0,1
DeviceB,Sprint,1,0,1,0
DeviceC,Sprint,0,1,0,0
DeviceD,Sprint,0,1,0,0
DeviceE,Sprint,0,1,0,0
DeviceF,Verizon,1,1,0,1
DeviceG,Verizon,1,0,1,0
DeviceH,Verizon,0,1,0,0
DeviceI,Verizon,0,1,0,0
DeviceJ,Verizon,0,1,0,0
DeviceK,Tmobile,1,1,0,1
DeviceL,Tmobile,1,0,1,0
DeviceM,Tmobile,0,1,0,0
DeviceN,Tmobile,0,1,0,0
DeviceO,Tmobile,0,1,0,0

plans Table


plan_id
vendor_id
name

Sample Data:

plan_id,vendor_id,name
PlanA,Sprint,Big Data Only Plan
PlanB,Verizon,Small Data Only Plan
PlanC,Sprint,300 Min Plan
PlanD,Verizon,900 Min Plan
PlanE,Verizon,Big Data Only Plan
PlanF,Tmobile,Small Data Only Plan
PlanG,Tmobile,300 Min Plan
PlanH,Tmobile,1000 Min Plan

plan_restrictions Table


restriction_id
vendor_id
plan_id
type
value

Sample Data:

restriction_id,vendor_id,plan_id,type,value
1,Sprint,PlanA,radio,3G
2,Sprint,PlanA,device_type,data
3,Verizon,PlanB,radio,4G
4,Sprint,PlanC,radio,3G
5,Sprint,PlanC,device_type,voice
6,Verizon,PlanD,radio,3G
7,Verizon,PlanD,device_type,voice
8,Verizon,PlanE,radio,3G
9,Verizon,PlanE,device_type,voice
10,Tmobile,PlanF,device_type,data
11,Tmobile,PlanG,device_type,voice
12,Tmobile,PlanH,device_type,voice

Restrictions keyed (I have closer to 50 actually, here is a same type of representation):


type / value possibilities
radio / 3g, 4g
device_type / data, voice

I am open to the possibility of restructuring the tables to make it easier to re-query, however I need to retain a certain amount of flexibility since I do have about 1000 models, 1000 plans, and about 2000 restrictions.

I personally think there is some sort of structure issue here, ie. models perhaps should have their elements as key/value pairs in a separate table, but that is even more complexity, and I haven’t determined yet how to properly apply data driven restrictions in the first place.

  • 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-17T11:02:58+00:00Added an answer on June 17, 2026 at 11:02 am

    I kicked this around for about the last hour with the other dba’s here and think I solved it. I am posting this for anyone who finds themselves in a similar situation. The biggest problem was that I was too close to the data, and was trying enforce “meaningful” properties and restrictions between the plans needs and the models properties.. which isn’t really necessary.

    I can restructure my data to be in the following tables:

    • Plans
    • Restrictions
    • Models

    • Plans would have a many to many relationship to Restrictions
    • Models would have a many to many relationship to Restrictions

    I would solve the many to many relationships with intirum tables

    • Plans_Restrictions
    • Models_Restrictions

    This would allow me to have stupid “Restrictions” such as a “Red Thing”

    I would query as a chain:

    • Plans
    • Plans_Restrictions
    • Restrictions
    • Models_Restrictions
    • Models

    ie. To get all models with their properties information (restriction info) that are eligible for a plan I could use:

    SELECT 
        M.* 
        ,R.*
    FROM (
        SELECT P1.*
        FROM Plans P1
        WHERE id_vendor = @id_vendor
    ) P
    
    INNER JOIN Plans_Restrictions PR
    ON P.plan_id = PR.plan_id
    
    INNER JOIN Restrictions R
    ON PR.property = R.property
    
    INNER JOIN Model_Restrictions MR
    ON R.property = MR.property
    
    INNER JOIN Model M
    ON MR.model_id = M.model_id
    

    And to get all the plans that are eligible for a model, i would reverse the 5 table chained join.

    Thanks Abe.. writing this all down in detail to explain it, and understanding why your suggestion didn’t solve my problem really helped me understand what my problem was and what I really needed to do. I don’t think I would have solved it so fast without you.

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

Sidebar

Related Questions

I have been working to build a complex data structure which would return a
I have a fairly complex data model and consequently a fairly complex query (using
I have a complex Query (Without any locking hints) that takes data from many
I have a complex data structure (user-defined type) on which a large number of
I have a complex Clojure data structure that I would like to serialize -
I have a more-or-less complex data structure (list of dictionaries of sets) on which
I have a multithreaded C++ application which holds a complex data structure in memory
Im not entirely sure what the name of this type of data structure (a
I have complex data structure, like this: OrderedHash, keys are dates and values are
I have a complex data structure along with some other data fields that used

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.