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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:07:09+00:00 2026-05-27T15:07:09+00:00

I am looking at using a SQL software to store and query objects with

  • 0

I am looking at using a SQL software to store and query objects with a loose schema.

We know that an object corresponds to a row of an SQL table, and it’s attributes correspond to columns. By ‘loose schema’, I mean that an object can have attributes that are not hardwired to the table’s (rather tables’) structure. An arbitrary (attribute,value) can be attached to an object.


Let me illustrate with a specific example:

For the given objects:

<subject>
name:data structures
tag:CS 
description:easy
desired_seniority:5.0

<subject>
name:microprocessors
tag:CS,electronics        <multi-valued
description:easy
desired_seniority:5.5     <numeric

and

<teacher>
name:John Doe
tag:electronics
seniority:5.8

The query will be

For each teacher, 
return all subjects whose tags match and 
whose desired seniority is less than or equal to the teacher's

The teacher ‘John Doe’ will be matched with subject ‘microprocessors’ because they share the tag ‘electronics’ and his seniority 5.8 is greater than the subject’s desired seniority 5.5

Note that I have used numeric (queries do comparison) and multi-valued (queries do an ‘is in’ match) string in the strings.


What exactly: I am looking for the right data model and corresponding queries that lets me simulate a loose schema on a SQL software.


I accept these constraints:

  1. teacher and subject may be described by distinct tables
  2. there will be one to one correspondence of attributes (if a query uses attribute ‘x’, all rows have attribute ‘x1’ and ‘x2’ of same type)

I saw http://www.igvita.com/2010/03/01/schema-free-mysql-vs-nosql/ and https://github.com/jamesgolick/friendly .


Yes, there are NoSQL databases and special ORMs. We use Solr (it’s great!). But I would avoid increasing the complexity of the project by including them. The performance overhead of emulating a noSQL store is not a concern.

  • 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-27T15:07:10+00:00Added an answer on May 27, 2026 at 3:07 pm

    In MySql I would use something like this:

    CREATE TABLE IF NOT EXISTS `subject` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `name` varchar(100) NOT NULL,
      `description` varchar(255) NOT NULL,
      `desired_seniority` decimal(5,2) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
    
    
    INSERT INTO `subject` (`id`, `name`, `description`, `desired_seniority`) VALUES
    (1, 'data structures', 'easy', 5.00),
    (2, 'microprocesors', 'easy', 5.50);
    
    CREATE TABLE IF NOT EXISTS `subject_tag` (
      `subject_id` int(10) unsigned NOT NULL,
      `tag_id` int(10) unsigned NOT NULL,
      PRIMARY KEY (`subject_id`,`tag_id`),
      KEY `fk_subject_tag_tags` (`tag_id`),
      KEY `fk_subject_tag_subject` (`subject_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    
    INSERT INTO `subject_tag` (`subject_id`, `tag_id`) VALUES
    (1, 1),
    (2, 1),
    (2, 2);
    
    CREATE TABLE IF NOT EXISTS `tag` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `name` varchar(100) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
    
    
    INSERT INTO `tag` (`id`, `name`) VALUES
    (1, 'CS'),
    (2, 'Electronics');
    
    
    CREATE TABLE IF NOT EXISTS `teacher` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `name` varchar(50) NOT NULL,
      `surname` varchar(50) NOT NULL,
      `seniority` decimal(5,2) DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
    
    
    INSERT INTO `teacher` (`id`, `name`, `surname`, `seniority`) VALUES
    (1, 'John', 'Doe', 5.80),
    (2, 'John', 'Brown', 5.30);
    
    
    
    CREATE TABLE IF NOT EXISTS `teacher_tag` (
      `teacher_id` int(10) unsigned NOT NULL,
      `tag_id` int(10) unsigned NOT NULL,
      PRIMARY KEY (`teacher_id`,`tag_id`),
      KEY `fk_teacher_tag_tag1` (`tag_id`),
      KEY `fk_teacher_tag_teacher` (`teacher_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    INSERT INTO `teacher_tag` (`teacher_id`, `tag_id`) VALUES
    (1, 2);
    
    
    ALTER TABLE `subject_tag`
      ADD CONSTRAINT `fk_subject_tag_tag` FOREIGN KEY (`tag_id`) REFERENCES `tag` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
      ADD CONSTRAINT `fk_subject_tag_subject` FOREIGN KEY (`subject_id`) REFERENCES `subject` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
    
    ALTER TABLE `teacher_tag`
      ADD CONSTRAINT `fk_teacher_tag_tag` FOREIGN KEY (`tag_id`) REFERENCES `tag` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
      ADD CONSTRAINT `fk_teacher_tag_teacher` FOREIGN KEY (`teacher_id`) REFERENCES `teacher` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
    

    And to get teachers with matched subjectes:

    SELECT t.surname, t.name, GROUP_CONCAT( s.name SEPARATOR ' | ' ) AS subject_name
    FROM teacher t
    JOIN teacher_tag tt ON tt.teacher_id = t.id
    JOIN subject_tag st ON st.tag_id = tt.tag_id
    JOIN subject s ON st.subject_id = s.id
    AND s.desired_seniority <= t.seniority
    GROUP BY t.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for help using sum() in my SQL query: SELECT links.id, count(DISTINCT stats.id)
I'm using sql server 2005/2008 and I have a table that it's PK (rec_index)
I'm looking for something equivalent to TRUNCATE TABLE How I do this using SQL
I am looking for a more sophisticated way of using Linq to SQL. I
I am looking to manage a SQL Server 2008 DB using Management Studio 2005.
I'm using WCF, SQL Server and ADO.NET. I'm looking at two implementation options for
I'm looking at using OpenID for my authentication scheme and wanted to know what
I'm using SQL Server 2005. I'm looking at opening a SQL connection, looping though
I am using SQL Server 2008 Enterprise. I am looking for a database backup
I am looking at using SQL Azure and wondering if it supports the FILESTREAM

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.