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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:07:30+00:00 2026-05-21T23:07:30+00:00

I am trying to create a mySql query to return a list of orders

  • 0

I am trying to create a mySql query to return a list of orders where they do not have a rate assigned to them. Currently I have:

SELECT * FROM Order
RIGHT JOIN Region ON Region.RegionID = Order.RegionID
LEFT JOIN RateSet ON RateSet.OrderID  = Order.OrderID  
LEFT JOIN Rate ON Rate.SalesID = RateSet.RateSetID
WHERE Rate.RateID IS NULL

The above query seems to achieve this however I want to take it one step further and only return orders where all orders in the region do not have a rate.

Greatly appreciate any help

  • 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-21T23:07:31+00:00Added an answer on May 21, 2026 at 11:07 pm

    Unusual situation – and I’m not at all sure that I understand why you have a RIGHT JOIN in amongst the LEFT JOIN conditions; it is the sort of thing that short-circuits my brain.

    You have 4 tables:

    • Order – columns OrderID, RegionID, …
    • Region – columns RegionID, …
    • Rate – columns RateID, SalesID, …
    • RateSet – columns RateSetID, OrderID, …

    We can guess that for table Xyz, the XyzID column is the primary key of the table. We can guess that a PqrID column in the table references table Pqr (except for SalesID, which does not have a corresponding table Sales – but it does seem to be a foreign key for joining Rate and RateSet (a puzzling inconsistency in the schema).

    It would have been helpful to provide this information in the question. You might have got an answer quicker that way, too.

    A given order seems to have one (possibly several) rate sets associated with it. Given the name, it appears that a given rate set can have a number of rates associated with it, including zero. It is not clear whether an order can be created without any associated rate sets, so we’ll take the conservative view that it can happen.

    I don’t think that we need to select from Region; the RegionID in the orders table is sufficient identification of the region. The following query lists the order information for each Order where there is either no information in the RateSet table or no information in the Rate table for the RateSet.

    SELECT DISTINCT O.*
      FROM      Order   AS O
      LEFT JOIN RateSet AS S ON S.OrderID  = O.OrderID  
      LEFT JOIN Rate    AS T ON T.SalesID  = S.RateSetID
     WHERE T.RateID IS NULL
    

    Now, which regions have one or more orders, but not one of the orders for that region have a rate?

    SELECT G.RegionID
      FROM Region AS G
     WHERE NOT EXISTS
           (SELECT DISTINCT O.RegionID
              FROM Order AS O
              JOIN RateSet AS S ON O.OrderID   = S.OrderID
              JOIN Rate    AS T ON S.RateSetID = T.SalesID
           )
    

    The sub-select lists the RegionID values of orders that have a rate assigned – using inner joins means that only rows with a rate will be selected. The regions not in that list are the only ones that are a candidate for ‘regions where none of the orders have a rate’. So we join that table with the previous query:

    SELECT DISTINCT O.*
      FROM      Order   AS O
      LEFT JOIN RateSet AS S ON S.OrderID  = O.OrderID  
      LEFT JOIN Rate    AS T ON T.SalesID  = S.RateSetID
      JOIN (SELECT G.RegionID
              FROM Region AS G
             WHERE NOT EXISTS
                   (SELECT DISTINCT O.RegionID
                      FROM Order AS O
                      JOIN RateSet AS S ON O.OrderID   = S.OrderID
                      JOIN Rate    AS T ON S.RateSetID = T.SalesID
                   )
            )           AS K ON O.RegionID = K.RegionID
     WHERE T.RateID IS NULL
    

    The schema structure is sufficiently unusual that I’m not sure about this – but it looks right.

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

Sidebar

Related Questions

Im trying to create a function, that will return a mysql query, which i
I trying to create a MySql Query from the $_POST values trouble is i
I'm trying to create a simple database table using the PHP MySQL query Create
i am trying to return a list of users whose accounts have expired from
I am trying to reconstruct a database query I created for MySQL in Microsoft
Im trying to create relationships between four tables in MySql: mainnodes (ID) subnodes (ID)
I am trying to create a table in MySql using php. My code looks
Im trying to create a iPhone Objective C login page using PHP/MySQL to authenticate.
I'm trying to convert my MySQL create table statements to SQLite create table statements.
I am trying to create a composite key for MYSQL, but i dont know

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.