Home News Contact Us Forum About Us Demos Products F.A.Q.
Shopping Cart
You currently have 0 items in your cart.


Recent Events
  • 31/12/2023 New Year SALE

    We are glad to announce New Year SALE. 25% discount for all our extensions. Use NY24 coupon code. Hurry up the discount is valid till 7 January.

  • 21/11/2023 BLACK FRIDAY 23 is coming

    BIG SALE, 35% discount for all our extensions. Use BF23 coupon code. Hurry up the discount is valid till 27 November.


2Checkout.com, Inc. is an authorized retailer of goods and services provided by ARI Soft. 2CheckOut




Follow us on twitter



Welcome, Guest
Please Login or Register.    Lost Password?

JOIN TABLE wrong entries amount
(1 viewing) (1) Guest
Go to bottomPage: 1
TOPIC: JOIN TABLE wrong entries amount
#55069
JOIN TABLE wrong entries amount 8 Years, 10 Months ago Karma: 0
I have 3 tables which I need to join.

Table animal is the main table. It contains:
Code:

LONG_ID | NAME | BREED_ID | BIRTH_DATE | FATHER_ID | KK


Table fathers is table which contains data about father. It is related to table animal by FATHER_ID. It looks like that:
Code:

FATHER_ID | LONG_ID | FATHER_NAME


Table breed is table which contains data about breed. It is related to table animal by BREED_ID. It looks like that:
Code:

BREED_ID | BREED_NAME | BREED_CODE


What I need is to display table which would look like that:
LONG ID(animal table) | NAME(animal table) | BREED NAME(breed table where BREED_ID = BREED_ID(from animal table)) | FATHER ID (animal table) | FATHER NAME (father table where FATHER_ID = FATHER_ID(from animal table)

For that I am using this sql query:
SELECT a.LONG_ID, a.NAME, b.BREED_NAME, a.FATHER_ID, f.FATHER_NAME
FROM animal a
LEFT JOIN breed b ON b.BREED_ID = a.BREED_ID
LEFT JOIN fathers f ON f.FATHER_ID = a.FATHER_ID;



And my table shows 3,064 entries but there are only 1,773 entries in animal table. Many double entries appears in data table. Why? Is my sql query wrong?
The administrator has disabled public write access.
 
#55070
Re:JOIN TABLE wrong entries amount 8 Years, 10 Months ago Karma: 0
All I needed was to add

Code:

GROUP BY
    a.LONG_ID

The administrator has disabled public write access.
 
#55071
Re:JOIN TABLE wrong entries amount 8 Years, 10 Months ago Karma: 747
Hello,

It seems duplicate records are located in "fathers" or/and in "breed" table(s). We can check it if you send an SQL dump of your tables or provide a temporary access to your J! backend by email so we can investigate the problem in more details.

As a temporary solution you can try the following query:

Code:


SELECT 
  a.LONG_ID, 
  a.NAME,
  b.BREED_NAME, 
  a.FATHER_ID, 
  f.FATHER_NAME 
FROM 
  animal a LEFT JOIN breed b 
    ON b.BREED_ID = a.BREED_ID
  LEFT JOIN fathers f 
    ON f.FATHER_ID = a.FATHER_ID
GROUP BY
  a.LONG_ID



Regards,
ARI Soft
The administrator has disabled public write access.
 
Go to topPage: 1