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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:34:06+00:00 2026-05-22T14:34:06+00:00

I have this query which runs fine: SELECT count(distinct p.products_id) as total FROM (products

  • 0

I have this query which runs fine:

SELECT count(distinct p.products_id) as total 
FROM (products p 
        LEFT JOIN manufacturers m 
        USING(manufacturers_id), products_description pd, 
              categories c, products_to_categories p2c ) 
LEFT JOIN meta_tags_products_description mtpd 
          ON mtpd.products_id= p2c.products_id 
          AND mtpd.language_id = 1 
WHERE (p.products_status = 1 AND p.products_id = pd.products_id 
       AND pd.language_id = 1 AND p.products_id = p2c.products_id 
       AND p2c.categories_id = c.categories_id 
       AND (
            (pd.products_name LIKE '%3220%' 
             OR p.products_model LIKE '%3220%' 
             OR m.manufacturers_name LIKE '%3220%' 
             OR (mtpd.metatags_keywords LIKE '%3220%' 
                 AND  mtpd.metatags_keywords !='') 
             OR 
             (mtpd.metatags_description LIKE '%3220%' 
              AND   mtpd.metatags_description !='') 
             OR 
              pd.products_description LIKE '%3220%'
            ) 
           ) 
      )

But I want to either search for those WHERE clauses or, given a numeric keyword value as in the example, search for the products id by just adding this to the previous query:

 OR (p.products_id=3220)

But for some reason that addition freezes the mysql server. It just keeps executing the query and it never ends. I have to manually restart the server. What is it that I am doing wrong?

  • 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-22T14:34:07+00:00Added an answer on May 22, 2026 at 2:34 pm

    When you add the OR to the end (assuming you’re adding it after the last paren), you are creating a cartesian join as you’re invalidating your JOIN conditions that you placed in your WHERE clause (p.products_id = pd.products_id, p.products_id = p2c.products_id and p2c.categories_id = c.categories_id). Also, why are you putting the initial tables (products, manufacturers, products_description, categories, products_to_categories) inside of parenthesis? Instead, try something more like this:

    SELECT count(distinct p.products_id) as total 
    FROM products p 
    LEFT JOIN manufacturers m USING(manufacturers_id)
    LEFT JOIN products_description pd using products_id
    LEFT JOIN categories c USING (categories_id)
    LEFT JOIN products_to_categories p2c USING (products_id)
    LEFT JOIN meta_tags_products_description mtpd 
              ON mtpd.products_id= p2c.products_id 
              AND mtpd.language_id = 1 
    WHERE (p.products_status = 1  
           AND pd.language_id = 1  
           AND (
                (pd.products_name LIKE '%3220%' 
                 OR p.products_model LIKE '%3220%' 
                 OR m.manufacturers_name LIKE '%3220%' 
                 OR (mtpd.metatags_keywords LIKE '%3220%' 
                     AND  mtpd.metatags_keywords !='') 
                 OR 
                 (mtpd.metatags_description LIKE '%3220%' 
                  AND   mtpd.metatags_description !='') 
                 OR 
                  pd.products_description LIKE '%3220%'
                ) 
               ) 
          )
          OR (p.products_id=3220)
    

    I do not understand what p.products_status = 1 AND pd.language_id = 1 mean in your case, so you may need to adjust how those are included in the JOIN.

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

Sidebar

Related Questions

I have the following oracle query which runs fine SELECT c.customercode, s.sales_id FROM customers
I have this query that runs fine: SELECT Value FROM data WHERE MetaDataID =
I have a query which looks like this: SELECT LossCost, CoverageID FROM BGILossCost] WHERE
I have this query which runs a join on Books, TradingDesks and ProductInfos. The
I have this sql query which runs fine when I execute it in MSSQL
This one has me rather confused. I've written a query which runs fine from
I have this query which groups the results by ORDER#. SELECT ORDER#, MAX(SHIPDATE -
I have the following query which runs fine on all of my sql server
I have an SQL LIKE query running on mySQL which runs fine on my
I have small PHP script which has $query = SELECT MAX(id) FROM `dbs`; //query

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.