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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:55:11+00:00 2026-05-16T08:55:11+00:00

I have a table of destinations ( states ) which contain primary level categories

  • 0

I have a table of destinations ( states ) which contain primary level categories and subcategories for activities. My ultimate goal is to output xml navigation links so I can link to:

  1. Each destination permalink ( ordered alphabetically by destination slug name )
  2. Each category underneath
  3. Each subcategories underneath the category

The below is what I’ll generate with the sql query, incase it has any bearing on the query but I don’t need xml help for this question:

<item href="/destinations/alabama/">
    <list>
        <item href="/destinations/alabama/category/">
            <list>
               <item href="/destinations/alabama/category/sub-category/"></item>
            </list>
        </item>
    </list>
</item>
<item href="/destinations/maryland/">
    <list>
        <item href="/destinations/maryland/category/">
            <list>
               <item href="/destinations/maryland/category/sub-category/"></item>
            </list>
        </item>
    </list>
</item>

Currently I have a query that grabs subcategories but it doesn’t account for active destinations.

SELECT

subcategories.name AS subcategory_name,
subcategories.slug AS subcategory_slug,
categories.name AS category_name,
categories.slug AS category_slug

FROM

subcategories

LEFT JOIN destinations_subcategories ON
destinations_subcategories.subcategory_id = subcategories.id

LEFT JOIN categories ON
destinations_subcategories.category_id = categories.id

WHERE
1=1 AND
subcategories.is_active = 1 AND
categories.is_active = 1

Which returns:

subcategory_name    subcategory_slug    category_name    category_slug
Fly Fishing         fly-fishing         Fishing          fishing

But this query doesn’t account for destinations which are active, since it’s possible to map relationships between inactive destinations and active categories. I’m thinking I need to maybe have a subquery grabbing all active destinations, then do the joining?

SCHEMA/row samples:

id    name       slug       active
7     Maryland   maryland   1

My categories table, sample row:

id    name       slug       active
1     Fishing    fishing    1

Subcategories table sample row:

id    name           slug           active
3     Fly-Fishing    fly-fishing    1

And 2 tables to store relationships, the first maps subcategories to categories:

id    category_id    subcategory_id
5     1              3

The second, destinations_subcategories maps destinations to subcategories:

id    destination_id   category_id    subcategory_id
5     7                1              3
  • 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-16T08:55:11+00:00Added an answer on May 16, 2026 at 8:55 am

    how about this

    SELECT
    
    subcategories.name AS subcategory_name,
    subcategories.slug AS subcategory_slug,
    categories.name AS category_name,
    categories.slug AS category_slug
    
    FROM
    
    destination 
    
    INNER JOIN destinations_subcategories on destination.id = destinations_subcategories.destination_id and destination.active = 1
    
    LEFT JOIN subcategories ON destinations_subcategories.subcategory_id = subcategories.id
    
    LEFT JOIN categories ON destinations_subcategories.category_id = categories.id
    
    WHERE 1=1 
    AND subcategories.is_active = 1 
    AND categories.is_active = 1
    

    This would make sure that only active destinations are shown

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

Sidebar

Related Questions

I have to develop a table that would contain distance between destinations and need
I have table in which I am inserting rows for employee but next time
I have table and this table contain result column with some entries. I just
I have a table on another SQL server which I need to copy from
I have a table in my database which essentially serves as a logging destination.
I currently have a Web Application which is using it's own Permissions table which
I have criteria saved within the records of a criteria table which I'm using
I have a table which have the following structure, the columns are origin, destination,
I have an XML file with data from a latin1 encoded, latin1_swedish_ci collated table
I have the Order table which contains information about a specific order, (when does

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.