Link to home
Start Free TrialLog in
Avatar of Panos
PanosFlag for Germany

asked on

SQL query Left Join problem

Hello experts.
I need help to get an output from 3 tables.
i'm using the Left Join but i do something wrong.
I details.
I have three tables:
1. product_types
product_types_id   product_types_name  product_types_image

2.taxes
Countrytax   Product_type_id   taxrate

3.countries
id  countryCode

the table .taxes can have multiple records for one Countrytax  like :
72      2     20.0
72      3      15.0 ......

The output i need is to show for one country the producttypes and taxes like:

UK   clothes  10% - shoes   20%  books   15%.....<br>
DE   clothes  5% - shoes   10%  books   12%.....<br>

The query i'm using now is showing me this vertical:
UK   clothes  10%
UK   shoes   20%
UK   books   15%

Any help?

<cfquery name="getcountries" datasource="#request.dsn#">
  SELECT t.taxrate,t.countrytax,c.countrycode,pt.product_types_name,pt.product_types_image,t.Product_type_id
  FROM taxes t
      LEFT OUTER JOIN product_types pt ON pt.product_types_id = t.Product_type_id
      LEFT JOIN countries c ON c.id = t.countrytax
  </cfquery>
  <cfoutput query="getcountries" group="product_type_id">
  #countrycode# ,#product_types_name#,#taxrate#<br>
  </cfoutput>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Panos

ASKER

Hi agx.
Nice to see you again.
Thank you for your help.It is working now.
Avatar of Panos

ASKER

Thank you
regards
panos
Great!