Hey,
I’m trying to get 2 queries to act as one but I am not sure how to go about it. Below I explain why and what I am working with. I hope this helps. Ty for your time.
Purpose:
The reason I need to combine 2 queries is because I have to list products to the public based on ‘best sellers’ over the past 2 months (which I can do, just fine, with one query - listed as Query 1 below) but I also have to add products, with ZERO sales, added by the admin, to that SAME list and page through ALL of those records (Query 2 listed below Query 1). That’s my dilemma…
Tables Involved: products, sales
Fields Involved (most important ones)
-
For Table Sales: prod_id,stamp (date of purchase)
-
For Table Product: ID, total_sales,marketplace_ready
Query 1: (Which works fine by itself - I am using ‘…’ to condense it/hide redundant fields)
SELECT DISTINCT prod_id, count( prod_id ) AS sales... FROM sales JOIN products ON ( products.ID = sales.prod_id ) where products.ID > '0' AND stamp >1268798400 GROUP BY title ORDER BY stamp DESC
Works great and displays 70 records now. This is how I can list top sellers of the last 2 months (the stamp is one that was properly dated a few moments ago) without fail. Below is the query used to pull products added by the admin to allow permission to be viewed in the marketplace even if they have 0 sales.
Query 2:
Table: products (same fields that are listed above are in play)
SELECT * FROM products where products.ID > '0' AND total_sales = '0' AND marketplace_ready = 'yes' group by title ORDER BY ID ASC
Total Records: 23 (as of this posting)
GOAL:
The idea is to just combine BOTH queries, into ONE, so I can get all 93 results (70 from Query 1 and 23 from Query 2) so I can use PAGING properly.
Do I use a regular join? Union statement?
Ty.