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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:06:24+00:00 2026-06-07T06:06:24+00:00

I have been trying to figure out this query for a few hours now

  • 0

I have been trying to figure out this query for a few hours now without success.

I have 3 tables:
– jstyle_category
– style
– subsite_style_alias

the tables have this schema:

  • jstyle_category:
    • style_id
    • category_id
    • subsite_id (INT)
    • sort_order
    • active (ENUM: y,n)
  • style
    • id
    • subsite_id (STRING, comma separated)
    • active (ENUM: y,n)
    • currently_available_for_sale (ENUM: y,n)
    • style_type_id
    • date_active (DATETIME)
  • subsite_style_alias
    • style_id
    • pos
    • show
    • subsite_logo_group_id
    • subsite_id (INT)

The records are something like

  • jstyle_category
    • 1234, 27, 572, 0, y
    • 8800, 27, 572, 1, y
    • 8800, 23, 953, 0, y
    • 8500, 23, 572, 0, y
  • style
    • 1234, 572, y, y, 99, 0000-00-00
    • 8800, 123, y, y, 99, 0000-00-00
    • 8500, 572, y, y, 99, 0000-00-00
  • subsite_style_alias
    • 8800, 0, y, 2589, 572
    • 8800, 1, y, 3475, 572
    • 8800, 1, y, 9554, 368

what I need a subset that contains all the items in jstyle_category where category_id = 27 with the data from subsite_style_alias if present (and this part I have done it with the following query). My Real problem is that currently I am getting something like:

  • 27, 0, 1234, NULL, NULL
  • 27, 0, 8800, 0, 2589
  • 27, 1, 8800, 1, 3475

What I need is the 8800 where there is no corresponding subsite_style_alias, so the final result will be

  • 27, 0, 1234, NULL, NULL
  • 27, 1, 8800, NULL, NULL
  • 27, 0, 8800, 0, 2589
  • 27, 1, 8800, 1, 3475

I know I am close to the answer, I just can’t figure it out.

I am also trying to avoid Unions if possible and rather use joins of the same tables

SELECT  jstyle_category.category_id category_id,
    jstyle_category.sort_order category_pos,
    style.id style_id,
    subsite_style_alias.pos pos,
    subsite_style_alias.subsite_logo_group_id
FROM  `jstyle_category` 
    LEFT JOIN style ON style.id = jstyle_category.style_id
    LEFT JOIN subsite_style_alias ON style.id = subsite_style_alias.style_id AND subsite_style_alias.subsite_id = 572
WHERE 
(

    (
        style.subsite_id = ""  OR 
        FIND_IN_SET("0",style.subsite_id) OR 
        FIND_IN_SET("572",style.subsite_id)
    ) AND 

    (
        subsite_style_alias.`active` = "y"  OR 
        subsite_style_alias.`active` IS NULL 
    ) AND 
    style.active = "y"  AND 
    style.currently_available_for_sale = "y"  AND 
    style.style_type_id NOT IN (7,10,11)  AND 
    jstyle_category.category_id = 27  AND 
    jstyle_category.subsite_id IN (0,572)  AND 
    jstyle_category.active = "y"  AND 

    (
        style.date_active IS NULL  OR 
        style.date_active <= "2012-02-24 18:00:00" 
    )
)
GROUP BY subsite_style_alias.subsite_logo_group_id,
    style.id
ORDER BY category_pos, subsite_style_alias.pos IS NULL,
    subsite_style_alias.pos,
    style.id

Thank you

  • 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-06-07T06:06:25+00:00Added an answer on June 7, 2026 at 6:06 am

    I solved by adding a new table formed by just NULL and then adding extra logic in the WHERE

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

Sidebar

Related Questions

Im stuck, been trying to figure this out for 2 hours now. I have
I have been scratching my head for hours trying to figure out why this
I have this query that i've been trying to figure out how to convert
I have been trying to figure this problem out without asking for help, but
I've been trying to figure this out for a few days now. Could someone
I have been trying to figure this out for quite a while, but what
I have been trying to figure this out for way to long tonight. I
I have been trying to figure this out for some time. It seems lots
So I have been trying to figure this out for a while, but nothing
I have been trying to figure out why I am getting this problem and

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.