'Why does my table join return values I didn't specify?

I am attempting to join two tables to create a visualization that shows the relationship between weight, BMI, and total steps using the following code:

SELECT
  Date AS date_join,
  TotalSteps AS Total_Steps,
  Weight,
  BMI AS BMI_join
FROM
  `bellabeat-case-study-347518.fitbit_data.activity` activity
JOIN
  `bellabeat-case-study-347518.fitbit_data.weight` weight
ON
  activity.Id = weight.Id
  AND activity.ActivityDate = weight.Date
ORDER BY
  TotalSteps DESC;

However, the results returned do not just give me the values associated with weight:

Row
date_join
Total_Steps
Weight
BMI_join
 1 
 2016-04-16 
 29326 
Id
Date
Weight
BMI
 8877689391 
 2016-04-16 
 188.5 
 25.59 
 25.59 
 2 
 2016-04-30 
 27745 
Id
Date
Weight
BMI
 8877689391 
 2016-04-30 
 188.5 
 25.59 
 25.59 
 3 
 2016-04-27 
 23629 
 { "Id": "8877689391", "Date": "2016-04-27", "Weight": "188.27", "BMI": "25.56" }
 25.56 
 4 
 2016-04-12 
 23186 
 { "Id": "8877689391", "Date": "2016-04-12", "Weight": "189.16", "BMI": "25.68" }
 25.68 
 5 
 2016-05-06 
 21727 
 { "Id": "8877689391", "Date": "2016-05-06", "Weight": "187.39", "BMI": "25.44" }
 25.44 
 6 
 2016-05-11 
 21420 
 { "Id": "8877689391", "Date": "2016-05-11", "Weight": "188.27", "BMI": "25.56" }
 25.56 

How can I get only the weight returned so that I can use the values in Tableau?



Solution 1:[1]

I realized the datatype for the Weight column was RECORD, so I used the CAST function to change it to an INTEGER. The following code ran perfectly:

SELECT
  Date AS date_join,
  TotalSteps AS Total_Steps,
  CAST(weight.Weight AS INTEGER) AS Weight_lbs,
  BMI AS BMI_join
FROM `bellabeat-case-study-347518.fitbit_data.activity` activity 
RIGHT OUTER JOIN `bellabeat-case-study-347518.fitbit_data.weight` weight 
ON activity.Id = weight.Id 
AND activity.ActivityDate = weight.Date
ORDER BY TotalSteps DESC;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ana Watkins