Jump to content

Double Left Join Duplicating Rows


klepec

Recommended Posts

Hello guys,

this is my query with two left joins (tried to join bcompany - main table WITH bpoint and bug):

SELECT cName, cAddr, sName, uNaslov FROM bcompany c LEFT JOIN bpoint p ON c.companyID = p.companyID LEFT JOIN bug b ON c.companyID = b.cID WHERE c.companyID='$cID';

 

 

First table bcompany is a main one, and there is always exactly one result row.

Both tables bpoint and bug relate to bcompany via the companyID column. These two tables will not necessarily have any records.

Thats why i used left joins, to always get the information of bcompany table no matter if there are any results in other tables or not.

 

 

My problem are doubled results of those two joined tables. I can understand multiple results for the main table, but not for the joined two.

How can i get rid of them?

 

Output:

 

bcompany:

Mladi Tehnik d.o.o.

Mladi Tehnik d.o.o.

Mladi Tehnik d.o.o.

Mladi Tehnik d.o.o.

Mladi Tehnik d.o.o.

Mladi Tehnik d.o.o.

Mladi Tehnik d.o.o.

Mladi Tehnik d.o.o.

Mladi Tehnik d.o.o.

Mladi Tehnik d.o.o.

Mladi Tehnik d.o.o.

Mladi Tehnik d.o.o.

 

bpoint:

Stari Tehnik

Stari Tehnik

Stari Tehnik

Pizzerija 5ka

Pizzerija 5ka

Pizzerija 5ka

Gostilna Kekec

Gostilna Kekec

Gostilna Kekec

Blejski Tehnik

Blejski Tehnik

Blejski Tehnik

 

 

bug:

Testna 1

Testna 2

Mickino kolo

Testna 1

Testna 2

Mickino kolo

Testna 1

Testna 2

Mickino kolo

Testna 1

Testna 2

Mickino kolo

Link to comment
Share on other sites

I want to display it like this:

 

Company title:

Mladi Tehnik d.o.o.

 

Company branches:

Stari Tehnik

Pizzerija 5ka

Gostilna Kekec

Blejski Tehnik

 

Company products:

Testna 1

Testna 2

Mickino Kolo

 

 

The main issue that im having is the duplicated results. I want every entry to be displayed only once. (Like shown above).

 

Thanks

Edited by klepec
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.