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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:21:22+00:00 2026-06-15T04:21:22+00:00

I’m lost with an MySQL query (running MySQL 5.0.88 ) I have two tables,

  • 0

I’m lost with an MySQL query (running MySQL 5.0.88)

I have two tables, one with products from different brands, the other one with applications (= applications filter products, so not every application displays every product).

I’m trying to query to get a list of brands depending on the application the user is running like so:

SELECT    p.brand_name
        , p.id
        , p.seller_id
        , a.seller_id
        , a.info  
        , a.name
        , a.application_match_keys  

    FROM  applications AS a 
    LEFT JOIN products AS p
        ON a.seller_id = p.seller_id    
        AND p.brand_name IN ( <<QueryString: application_match_keys>> )

    WHERE  p.active = "1"
    AND    a.seller_id = "2222222222222"

    GROUP BY p.brand_name
    ORDER BY p.brand_name ASC 

Problem is, once I do the left join I’m no longer getting correct results, so for example:

=== products ===
id        brand_name  seller_id
123       A           John
111       A           John
124       A           John
999       B           John
xx1       C           John

=== applications ===
name    seller_id   info  application_match_keys
red     John        foo   A
blue    John        bar   B,C

If the user is in application A, his brand list should only include brands from active products with corresponding match_keys (= A), so I would expect the query to return

p.brand_name  application   info
A             red           foo

But I’m always getting the correct brand name with mis-matched application data like so:

p.brand_name  application   info
A             blue          bar

Question:
Is there a way to query this in a single query, or do I have to query active products' brands with matching application key first and then loop/query again to get the application data I need? Must be possible in a single query, too?

Thanks for help!

EDIT:
Got it. This is how it works:

SELECT    p.brand_name
        , p.id
        , p.seller_id
        , a.seller_id
        , a.info  
        , a.name
        , a.application_match_keys 

FROM  applications AS a 
LEFT JOIN products AS p
    ON a.seller_id = p.seller_id
    AND p.brand_name IN ( <<QueryString: application_match_keys>> )
    AND FIND_IN_SET( a.application_match_keys, <<QueryString: application_match_keys>>) <> 0    

WHERE  p.active = "1"
AND    a.seller_id = "2222222222222"

GROUP BY p.brand_name
ORDER BY p.brand_name ASC 

Thank you very much!

  • 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-15T04:21:23+00:00Added an answer on June 15, 2026 at 4:21 am

    how about using FIND_IN_SET?

    AND FIND_IN_SET(p.brand_name, a.application_match_keys) <> 0
    
    • FIND_IN_SET
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tracked down a weird MySQL problem to the two different ways I was
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I am currently running into a problem where an element is coming back from
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites 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.