Click here to Skip to main content
15,741,752 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
SQL
SELECT Able.userid,Able.date,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
Posted
Updated 1-May-20 19:43pm
v3
Comments
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

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

SQL
SELECT A.userid, A.date, A.source, B.completed_team, C.send, C.open, C.click
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900