Query Result is Repeating The Records????????

  • Thread starter Malik via AccessMonster.com
  • Start date
M

Malik via AccessMonster.com

Hi,
I want to disscuss two Queries in Database. When I run Them Seperately, These
works Well, but When I Run them as a Union Query, The Data Is repeated
Several Times ....

Eg: Query1 Have 7 Records And Query2 Have 5 Recods.

Now I Made a Union Query, When I Run it, It Shows me The Data Repeated
Saveral Times.

Now It Will Show me "7*5" = 35 Records , And These Recors Have Repeated
Records.

Why is it Happening????
 
R

raskew via AccessMonster.com

It sounds as if you've created a Cartesian product. Please post your query
SQL.

Bob
 
M

malik via AccessMonster.com

raskew said:
It sounds as if you've created a Cartesian product. Please post your query
SQL.

Bob

SELECT QuerySales.SaleId, QuerySales.SaleDate, QuerySales.PartyId AS
QuerySales_PartyId, QuerySales.CommId, QuerySales.NoOfBags, QuerySales.Rate,
QueryVouchers.VoucherNo, QueryVouchers.VoucherDate, QueryVouchers.PartyId AS
QueryVouchers_PartyId, QueryVouchers.DrAmount, QueryVouchers.Narration
FROM (TblParties INNER JOIN QueryVouchers ON TblParties.PartyId =
QueryVouchers.PartyId) INNER JOIN QuerySales ON TblParties.PartyId =
QuerySales.PartyId;
 
R

raskew via AccessMonster.com

Where is the Union query in all of this?

Bob
SELECT QuerySales.SaleId, QuerySales.SaleDate, QuerySales.PartyId AS
QuerySales_PartyId, QuerySales.CommId, QuerySales.NoOfBags, QuerySales.Rate,
QueryVouchers.VoucherNo, QueryVouchers.VoucherDate, QueryVouchers.PartyId AS
QueryVouchers_PartyId, QueryVouchers.DrAmount, QueryVouchers.Narration
FROM (TblParties INNER JOIN QueryVouchers ON TblParties.PartyId =
QueryVouchers.PartyId) INNER JOIN QuerySales ON TblParties.PartyId =
QuerySales.PartyId;
 
M

malik via AccessMonster.com

raskew said:
Where is the Union query in all of this?

Bob
Is this not a Union Query. this Query Has Two Queries

If It not a Union Query, Then Plz Tell me how to creat a union Query.
 
S

Stefan Hoffmann

hi Malik,
SELECT QuerySales.SaleId, QuerySales.SaleDate, QuerySales.PartyId AS
QuerySales_PartyId, QuerySales.CommId, QuerySales.NoOfBags, QuerySales.Rate,
QueryVouchers.VoucherNo, QueryVouchers.VoucherDate, QueryVouchers.PartyId AS
QueryVouchers_PartyId, QueryVouchers.DrAmount, QueryVouchers.Narration
FROM (TblParties INNER JOIN QueryVouchers ON TblParties.PartyId =
QueryVouchers.PartyId) INNER JOIN QuerySales ON TblParties.PartyId =
QuerySales.PartyId;
A union query needs the UNION [ALL] clause to concatenate the output of
two or more queries.

You need to look for two things, if the query above returns more rows
than expected:

1. Have you chosen the correct fields as JOIN condition?
2. Does the data in the base tables contain the correct data?

These two questions imply that you have correct primary keys in all used
queries.


mfG
--> stefan <--
 
S

Stefan Hoffmann

hi,

Stefan said:
A union query needs the UNION [ALL] clause to concatenate the output of
two or more queries.
... more queries or tables.
These two questions imply that you have correct primary keys in all used
queries.
... in all used tables.


mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top