MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old May 6th, 2008, 01:20 PM
Tom Jones Tom Jones is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 85 Tom Jones User rank is Sergeant (500 - 2000 Reputation Level)Tom Jones User rank is Sergeant (500 - 2000 Reputation Level)Tom Jones User rank is Sergeant (500 - 2000 Reputation Level)Tom Jones User rank is Sergeant (500 - 2000 Reputation Level)Tom Jones User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 21 m 30 sec
Reputation Power: 10
How to Query this (Category/Subjects-in-Category/Titles-in-Subject)

I am struggling with the best way to query this. I have three tables, Categories, Subjects, and Titles. A Title belongs to only one Subject, a Subject belongs to only one Category. Inversely, Categories can have multiple Subjects, Subjects can have multiple Titles. Categories has a main_id, Subjects are linked to Categories by the main_id and also have a sub_id, Titles are linked to Subjects by the sub_id.

What I want to do is run (hopefully only one) query and then output all results like this:

Category
-Subject
--Title
-Subject
--Title
--Title
Category
-Subject
--Title
--Title
--Title
-Subject
...
So, I need to associate categories as the parent, subjects as the children of categories, and titles as the children of subjects.

Is this possible to do with one query? Is there a good tutorial anyone knows on how I would structure such a query?

Reply With Quote
  #2  
Old May 6th, 2008, 01:27 PM
jcarouth's Avatar
jcarouth jcarouth is offline
Never give up
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Sep 2005
Location: College Station, TX, USA
Posts: 2,606 jcarouth User rank is Brigadier General (60000 - 70000 Reputation Level)jcarouth User rank is Brigadier General (60000 - 70000 Reputation Level)jcarouth User rank is Brigadier General (60000 - 70000 Reputation Level)jcarouth User rank is Brigadier General (60000 - 70000 Reputation Level)jcarouth User rank is Brigadier General (60000 - 70000 Reputation Level)jcarouth User rank is Brigadier General (60000 - 70000 Reputation Level)jcarouth User rank is Brigadier General (60000 - 70000 Reputation Level)jcarouth User rank is Brigadier General (60000 - 70000 Reputation Level)jcarouth User rank is Brigadier General (60000 - 70000 Reputation Level)jcarouth User rank is Brigadier General (60000 - 70000 Reputation Level)jcarouth User rank is Brigadier General (60000 - 70000 Reputation Level)jcarouth User rank is Brigadier General (60000 - 70000 Reputation Level)jcarouth User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 1251 Folding Title: Novice Folder
Time spent in forums: 1 Month 2 Weeks 5 h 5 m 47 sec
Reputation Power: 693
Send a message via AIM to jcarouth Send a message via MSN to jcarouth Send a message via Yahoo to jcarouth Send a message via Skype to jcarouth
Facebook Orkut
while not exactly on point, the article Rudy authored on the subject should give you the general idea of the query structure. only in your example you aren't self-joining.
Comments on this post
Tom Jones agrees!
__________________
Jeff Carouth's Homepage
Accelerate Studio

have i been exceptionally helpful today? feeling generous?

Reply With Quote
  #3  
Old May 6th, 2008, 01:31 PM
Tom Jones Tom Jones is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 85 Tom Jones User rank is Sergeant (500 - 2000 Reputation Level)Tom Jones User rank is Sergeant (500 - 2000 Reputation Level)Tom Jones User rank is Sergeant (500 - 2000 Reputation Level)Tom Jones User rank is Sergeant (500 - 2000 Reputation Level)Tom Jones User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 21 m 30 sec
Reputation Power: 10
That looks promising, jcarouth!

I'll give it a reading (I obviously am not using the proper search terms in Google, I was looking for just such a page for the last 4 hours).

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > How to Query this (Category/Subjects-in-Category/Titles-in-Subject)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway