We help IT Professionals succeed at work.
Get Started

SQL query Left Join problem

Panos
Panos asked
on
284 Views
Last Modified: 2012-08-13
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

Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2015
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE