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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:18:21+00:00 2026-05-25T23:18:21+00:00

I think my problem is solved with a ‘recursive query’, but since MySQL doesn’t

  • 0

I think my problem is solved with a ‘recursive query’, but since MySQL doesn’t support recursive queries I was trying to use the adjacent list model. This should not be a problem since I know how deep I want to go.

Here’s an example of what I need to do:
Table Classes:

dept    classNum    prereqDept  prereqClassNum
BIO     465         BIO         335
EE      405         EE          325
EE      325         EE          120
BIO     465         EE          120
BIO     335         BIO         225
BIO     225         CHEM        110
BIO     225         BIO         105

What I need is all the classes of a certain level (let’s say 400) with all their prerequisites up to 3 levels deep.
So I’d get something like

dept    classNum    prereqDept  prereqClassNum
BIO     465         BIO         335
BIO     465         BIO         225
BIO     465         CHEM        110
BIO     465         BIO         105
EE      405         EE          325
EE      405         EE          120
....

I know I need to use 3-LEFT JOINs if I want to go 3 levels deep, but I can’t figure out how to set up these joins to get what I need.
Any ideas?
I’ll appreacite your help!

P.S. I can’t change the table structure at all.

  • 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-25T23:18:22+00:00Added an answer on May 25, 2026 at 11:18 pm

    Hmm. Try this:

    SELECT * FROM
    (
        (
            SELECT t1.dept, t1.classNum, t1.prereqDept, t1.prereqClassNum
            FROM class AS t1
            WHERE t1.classNum >= 400
        )
        UNION
        (
            SELECT t1.dept, t1.classNum, t2.prereqDept, t2.prereqClassNum
            FROM class AS t1
            JOIN class AS t2 ON (t1.prereqDept = t2.dept AND t1.prereqClassNum = t2.classNum)
            WHERE t1.classNum >= 400
        )
        UNION
        (
            SELECT t1.dept, t1.classNum, t3.prereqDept, t3.prereqClassNum
            FROM class AS t1
            JOIN class AS t2 ON (t1.prereqDept = t2.dept AND t1.prereqClassNum = t2.classNum)
            JOIN class AS t3 ON (t2.prereqDept = t3.dept AND t2.prereqClassNum = t3.classNum)
            WHERE t1.classNum >= 400
        )
    ) AS t4
    ORDER BY dept, classNum, prereqDept, prereqClassNum
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to solve this problem http://www.spoj.pl/problems/PEBBMOV/ . I think I have the
i have a problem that i can't solve ! (sqlite3, but i think it
Think my problem is I am trying to sum a count in the same
I'm not that good with this REGEX string replace, but i think this problem
I've been trying to install jpgraph to my hostgator website but there's a problem
Do interfaces solve the deadly diamond of death problem? I don't think so, for
I am new at JavaScript so I think my problem may be simple. This
I'm cross-posting this from the wordpress section, b/c I think the problem lies more
Simple problem (I think): I want to be able to invoke a click method
The problem I think is with returning an object when i overload the +

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.