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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:45:22+00:00 2026-05-25T03:45:22+00:00

I’m putting together a database structure that can hold data for courses. Each course

  • 0

I’m putting together a database structure that can hold data for courses. Each course – will have several chapters and each chapter MAY have topics and each topic MAY have sub topics and so on.

This is sample data

Course - Accounts
1) Introduction to Accounts
   a) Basic Accounts
2) Financial Statements
   a) Income statement
      i) Depreciation
   b) Cash Flow Statement
3) Career as an accountant 

Now each of these topics will have lecture notes associated with them. Now the way I’m thinking is incase of Chapter 1 – “Introduction” – the notes are going to be associated with the topic “Basic Accounts”. But in chapter 2 – “Income Statement” wont have any notes but “Depreciation” is going to have notes. Now since Chapter 3 “Career as Accountant” does not have any sub topics – the notes are going to be associated directly with it.

This is just my way or organizing – I can enforce rules saying each chapter must have a subtopic so notes can be associated etc.

This is what I have so far

Table: Course
course_id
course_name

Table: Topics
topic_id
parent_topic_id
topic_name
notes

Table: Course_Topics
course_id
topic_id

So the sample data would appear as

Course_id  |  Course Name
    1          Accounts

Topic_id  | Parent_topic_id  |   topic_name           | notes
    1             0             Introduction
    2             1             Basic Accounts
    3             0             Financial Statements
    4             3             Income Statements
    5             4             Depreciation

Course_id   |    Topic_id
    1               1
    1               2
    1               3
    1               4
    1               5

Here is what I’m looking for:
1) Is there a better way to design this – should I enforce stricter rules on how notes are associated with chapters or topics or sub topics

2) Secondly – given this data structure – if I wanted to pull all topics for a given course and display them in the chapter -> topic -> sub topic tree structure format. How would I do that. Should I just pull out all topics based on the course id and then in server side store them in data structures and organize them according to chapter/topic/subtopic wise or is there a cleaner way of doing it using sub queries.

Sorry for the long post – just wanted to clearly explain.
Thanks for your time

****** EDIT ********

Thanks for all the answers guy. I came across this other approach of adding a lineage column and a deep column to the table.

The approach is explained here as “Flat table model done right”
http://www.ferdychristant.com/blog/archive/DOMM-7QJPM7

What do you guys think of this approach.

Secondly - John raised a good point in his answer. How would I handle inserts in between.
- Chapters (parent_id =0) Say if I want to insert a new chapter between chapter 1 and 2
- Topic (parent_id != 0 ) If I want to insert a new topic between any two existing topics

Should I have another column that maintains the order like 1,2,3 and then if I want to insert something in between chapters 1 and 2 – insert it with a value 1.1 or something like that – can the same column be used for topics as well.

Thanks again

  • 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-25T03:45:23+00:00Added an answer on May 25, 2026 at 3:45 am

    Skip the table course_topics if it’s a one-to-many relationship.

    You can make it

    Table: Course
    course_id
    course_name
    
    Table: Topics
    topic_id
    parent_topic_id
    topic_name
    notes
    course_id
    

    Notes seems fine if it’s just one text field. If there are more you’ll need to branch it out to another table.

    Your 2nd question is very interesting… It can be done using a recursive join.
    ie you can use a CTE(Common table expression) to recursively join the table to itself. While displaying it just use a level field denoting which level in the hierarchy it is in and order it something like

    order level
    000   0
    000.1 1
    000.2 2
    001.1 0
    001.2 1
    

    Just search for hierarchical data in sql…
    Since u use mysql and if you think u want to go for adjacency list or nested list here’s an analysis.
    http://explainextended.com/2009/09/29/adjacency-list-vs-nested-sets-mysql/
    and also…. look at this question it explains a lot ->
    What are the options for storing hierarchical data in a relational database?

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have a reasonable size flat file database of text documents mostly saved in
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has

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.