Click here to Skip to main content
14,601,062 members
Rate this:
Please Sign up or sign in to vote.
See more:
I do have the following table

table Able
userid    date       source
 1010      4/20/2020   updown
 1012      3/20/2020   leftdown

Table Brake
userid    completed_team   crossing   purchase
  1010       tokyo            mapping    yes
  1012       New York         clive      yes

Table Cost
userid   _send  _open  _click  completed_team   
  1010     20     12      8          Only
  1012     12     8       6          Double

I'm trying to get a table that shows something like this

userid    date       source       send  open  click
1010      4/20/2020   updown       20     12      8
1012      3/20/2020   leftdown     12     8       6

What I have tried:

i've used this query, but it is returning duplicates even though there are no duplicates
SELECT Able.userid,,Able.ource,Brake.ompleted_team,cost.Send2,cost.Open2,cost.Click2
 from Brake
 left join Able on breake.userid= able.userid
 left join cost on able.userid= cost.userid
Updated 1-May-20 19:43pm
Tomas Takac 21-Apr-20 2:21am
With the data you show there should be no duplicates. Try to run this to see where it is duplicated:
select a.userid, b.userid, c.userid
from Able a
left join Brake b on b.userid = a.userid
left join Cost c on c.userid = a.userid
ZurdoDev 21-Apr-20 7:35am
Select all columns from all tables and then you can see where the duplicate is coming from.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You have to use parentheses to separate each join. The query would be like this:

SELECT A.userid,, A.source, B.completed_team, C.send,,
from (( B
left join A on B.userid = A.userid ) 
left join C on A.userid = C.userid);

The output of the above code will be:
userid	date	    source	 completed_team	send	open	click
1010	4/20/2020	updown	   Tokyo	     20	     12	     8
1012	3/20/2020	leftdown   New York	     12	     8	     6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100