mabino79201 (1 Viewer)

mabino79

Member
Local time
Today, 16:04
Joined
Nov 17, 2021
Messages
72
adding two query in one but getting duplicate records.

SELECT [qryReserveFolio Query].Product, [qryReserveFolio Query].Qty, qrySalesFolio.Qty
FROM [qryReserveFolio Query], qrySalesFolio;

can anyone help, as its showing duplicate values/ rows
 

Jon

Access World Site Owner
Staff member
Local time
Today, 11:34
Joined
Sep 28, 1999
Messages
7,525
Welcome to the forums! We are the most active Microsoft Access community on the internet by far, with posts going back over 20 years!

To get started, I highly recommend you read the post below. It contains important information for all new users to this forum.

https://www.access-programmers.co.uk/forums/threads/new-member-read-me-first.223250/

We look forward to having you around here, learning stuff and having fun!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:34
Joined
May 7, 2009
Messages
19,249
you create Join:

SELECT [qryReserveFolio Query].Product, [qryReserveFolio Query].Qty, qrySalesFolio.Qty
FROM [qryReserveFolio Query] Inner Join qrySalesFolio On [ [qryReserveFolio Query].Product = qrySalesFolio.Product
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:34
Joined
Oct 29, 2018
Messages
21,591
Hi. Welcome to AWF!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:34
Joined
Aug 30, 2003
Messages
36,139
Welcome aboard. I moved your thread to a more appropriate forum.
 

plog

Banishment Pending
Local time
Today, 05:34
Joined
May 11, 2011
Messages
11,676
Code:
SELECT [qryReserveFolio Query].Product, [qryReserveFolio Query].Qty, qrySalesFolio.Qty
FROM [qryReserveFolio Query], qrySalesFolio;

My guess is that you just need 1 correctly constructed query. Can you post the SQL of qryReserveFolio and qrySalesFolio?
 

mabino79

Member
Local time
Today, 16:04
Joined
Nov 17, 2021
Messages
72
SELECT [qryReserveFolio Query].Product, [qryReserveFolio Query].Qty, qrySalesFolio.Qty FROM [qryReserveFolio Query], qrySalesFolio;
1637388814960.png


getting repeated rows duplicate
 

plog

Banishment Pending
Local time
Today, 05:34
Joined
May 11, 2011
Messages
11,676
You didn't post the SQL I requested, but that Relationship Tool told me what I needed. You are essentially storing a piece of data in the name of your tables that should go into a field.

tblSalesFolio and tblReserveFolio should not be seperate tables, nor should tblPOFolio. The data from all three of those tables need to go into just 1 table--let's call it tblFolio--that has all the fields those tables have plus 1 more [FolioType]. In that field you will store if the record is for 'PO', 'Sales' or 'Reserve'.

Also, I bet you can combine tblPurchase, tblSales and tblReserve into 1 table as well, there's considerable overlap among their fields. Do that and there's no need for 2 seperate queries to being with you can just go straight to the final query.
 

mabino79

Member
Local time
Today, 16:04
Joined
Nov 17, 2021
Messages
72
You didn't post the SQL I requested, but that Relationship Tool told me what I needed. You are essentially storing a piece of data in the name of your tables that should go into a field.

tblSalesFolio and tblReserveFolio should not be seperate tables, nor should tblPOFolio. The data from all three of those tables need to go into just 1 table--let's call it tblFolio--that has all the fields those tables have plus 1 more [FolioType]. In that field you will store if the record is for 'PO', 'Sales' or 'Reserve'.

Also, I bet you can combine tblPurchase, tblSales and tblReserve into 1 table as well, there's considerable overlap among their fields. Do that and there's no need for 2 seperate queries to being with you can just go straight to the final query.
Ok thanks for your suggestion, will do and update
 

mabino79

Member
Local time
Today, 16:04
Joined
Nov 17, 2021
Messages
72
SELECT tblFolio.TypeofFolio, tblProducts.ProductCode, Sum(tblFolio.Qty) AS SumOfQty
FROM tblProducts INNER JOIN tblFolio ON tblProducts.ProductsID = tblFolio.Product
GROUP BY tblFolio.TypeofFolio, tblProducts.ProductCode;

getting the total nos. of, but can you tell me how to make the report for Product base Sale, Purchase & Reserved Qty separately

1637399736742.png
 

mabino79

Member
Local time
Today, 16:04
Joined
Nov 17, 2021
Messages
72
SELECT tblFolio.TypeofFolio, tblProducts.ProductCode, Sum(tblFolio.Qty) AS SumOfQty
FROM tblProducts INNER JOIN tblFolio ON tblProducts.ProductsID = tblFolio.Product
GROUP BY tblFolio.TypeofFolio, tblProducts.ProductCode;

getting the total nos. of, but can you tell me how to make the report for Product base Sale, Purchase & Reserved Qty separately

View attachment 96268

TRANSFORM Sum(qryProductPurchase.SumOfQty) AS SumOfSumOfQty
SELECT qryProductPurchase.Product, Sum(qryProductPurchase.SumOfQty) AS [Total Of SumOfQty]
FROM qryProductPurchase
GROUP BY qryProductPurchase.Product
PIVOT qryProductPurchase.TypeofFolio;


created CrossTabl Query,

if the value is Null than how to make zero so it can be calculated

1637402626259.png
 

mabino79

Member
Local time
Today, 16:04
Joined
Nov 17, 2021
Messages
72
TRANSFORM Sum(qryProductPurchase.SumOfQty) AS SumOfSumOfQty
SELECT qryProductPurchase.Product, Sum(qryProductPurchase.SumOfQty) AS [Total Of SumOfQty]
FROM qryProductPurchase
GROUP BY qryProductPurchase.Product
PIVOT qryProductPurchase.TypeofFolio;


created CrossTabl Query,

if the value is Null than how to make zero so it can be calculated

View attachment 96269
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:34
Joined
May 7, 2009
Messages
19,249
TRANSFORM Nz(Sum(qryProductPurchase.SumOfQty), 0) AS SumOfSumOfQty
...
...
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:34
Joined
Feb 28, 2001
Messages
27,427
It looks like you have actually fixed the duplicates problem. I want to highlight the cause for that condition so that others reading the post (and most important, you) will be able to recognize and avoid the error in the future. You posted this query. (I didn't include code markers because I want to use color highlights instead.)

SELECT [qryReserveFolio Query].Product, [qryReserveFolio Query].Qty, qrySalesFolio.Qty FROM [qryReserveFolio Query], qrySalesFolio;

The problem is highlighted in red. This query is perfectly legal in SQL, but you have to recognize what you are really requesting. You see, SQL is based on set theory. It will give you every possible combination of records from those two tables. In this query, you have what is called a Cartesian JOIN, and you may also see the name Permutation JOIN.

You got apparent duplication of some data because you did not constrain the selection and/or presentation of content from the two tables. You were advised to use JOIN ... ON syntax, which constrains SQL to only show you records that have some particular value in common with a field value in the other table. You will often see this concept - field from table A matching field from table B - described via a Relation. Technically, SQL still starts out preparing to give you all of the possible combinations - but it then immediately filters out the records for which the joined fields do not match, and that eliminates a lot of the "clutter" that usually comes back after a Cartesian JOIN. That will eliminate the apparent repetition.
 

mabino79

Member
Local time
Today, 16:04
Joined
Nov 17, 2021
Messages
72
on a crosstab query based report can we make a filter if the value is Zero or Null, row will be hide or removed.
 

mabino79

Member
Local time
Today, 16:04
Joined
Nov 17, 2021
Messages
72
TRANSFORM Nz(Sum(qryProductPurchase.SumOfQty), 0) AS SumOfSumOfQty
...
...
in a crosstab query based report can we make a filter

if the value is Zero or Null, that row will be hide or removed from the report
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:34
Joined
May 7, 2009
Messages
19,249
on the report, you can Change the Recordsource on the Open event.
since this is a crosstab you will need a function that will inspect each row
if the total is null or zero.
you call this function on your New Query (Query builder on Report) to include/exclude
those records.

see this demo.
when you open Query1, you'll see a blank record at the beginning.
this record is excluded from the sampleReport report.
 

Attachments

  • cross_tab.accdb
    656 KB · Views: 239
Last edited:

mabino79

Member
Local time
Today, 16:04
Joined
Nov 17, 2021
Messages
72
Required Sub Form Row Selected Product --> Total of Product Qty Purchased - Sales

in Main Form from Sub Form
 

Users who are viewing this thread

Top Bottom