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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:25:42+00:00 2026-06-13T06:25:42+00:00

I have the query below which works great. SELECT `Despatch`.`DespatchNumber` , `Despatch`.`Product` , `Stock`.`ProductNumber`

  • 0

I have the query below which works great.

    SELECT  `Despatch`.`DespatchNumber` , `Despatch`.`Product` ,
           `Stock`.`ProductNumber` ,  `Stock`.`Description` ,      
     `Stock`.`ProductGroup` ,  `Stock`.`Size` ,  `Stock`.`IPICODE`  , `Stock`.`Fit` ,  
     `Stock`.`62` 
            FROM Stock , Despatch 
            WHERE  `Despatch`.`DespatchNumber` = '" . $Despatch . "'   
            AND   `Despatch`.`Product`  =    `Stock`.`ProductCode`      

My problem is i want to expand it that im using the value of $Despatch to search another column in the same table using an OR function. So the query will look into Despatch Number and if it does not find one matching then it looks into order number as below. It doesnt work and my mysql server just hangs trying to run this query.

      SELECT  `Despatch`.`DespatchNumber` , `Despatch`.`Product` ,
           `Stock`.`ProductNumber` ,  `Stock`.`Description` ,  `Stock`.`ProductGroup` ,  `Stock`.`Size` ,  `Stock`.`IPICODE`  , `Stock`.`Fit` , `Stock`.`62` 
            FROM Stock , Despatch 
            WHERE  `Despatch`.`DespatchNumber` = '" . $Despatch . "'   
            OR  `Despatch`.`OrderNumber` = '" . $Despatch . "' 
            AND   `Despatch`.`Product`  =    `Stock`.`ProductCode`  
  • 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-13T06:25:43+00:00Added an answer on June 13, 2026 at 6:25 am

    You need parentheses around your OR clause:

    WHERE (`Despatch`.`DespatchNumber` = '" . $Despatch . "'   
    OR     `Despatch`.`OrderNumber` = '" . $Despatch . "') 
    AND   `Despatch`.`Product`  =    `Stock`.`ProductCode`  
    

    I’d also very strongly recommend you to explicitly use the JOIN keyword when you perform joins. Not only is this best practice, but it also would have prevented the error occuring in this case.

    SELECT -- ...columns...
    FROM Stock AS S
    JOIN Despatch AS D
    ON D.Product = S.ProductCode
    WHERE D.DespatchNumber = 'DN001234'
    OR D.OrderNumber = 'DN001234'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a select query which works correctly with the below output: I would
I have managed to write the below query, which works great. My problem is
I have the function below, which puts the query into an object. It works
I have a T-SQL query as below which queries a table holding the search
I'm using Sql-Server, and I have the below query which returns all columns that
I have a result from a query like the below, which does not have
The dynamica query I have below works but wondering if what I have below
I want to group the below query by GetSetDomainName and select the row which
I am trying to use the query below (which works perfectly), as a subquery
I have a SELECT statement similar to the one below which returns several counts

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.