BMLG Learning
BMLG Learning

Reputation: 59

SQL query malfunction

So Im trying to use INNER JOIN in my sql command because I am trying to replace the Foreign keys ID numbers with the text value of each column. However, when I use INNER JOIN, the column for "Standards" always gives me the same value. The following is what I started with

SELECT Grade_Id, Cluster_Eng_Id, Domain_Math_Eng_Id, Standard 
FROM `math_standards_eng` 
WHERE 1

and returns this (which is good). Notice the value of Standard values are different

 Grade_Id   Cluster_Eng_Id  Domain_Math_Eng_Id  Standard
 103           131                 107          Explain equivalence of fractions in special cases...
 104           143                 105          Know relative sizes of measurement units within o...

When I try to use Inner Join, the values for Grade_Id, Cluster_Eng_Id, and Domain_Math_Eng_Id are changed from numbers to actual text. Standard column values, however, seems to return the same value. Here is my code:

SELECT 
    grades_eng.Grade, domain_math_eng.Domain, cluster_eng.Cluster, 
    math_standards_eng.Standard 
FROM 
    math_standards_eng 
INNER JOIN 
    grades_eng ON math_standards_eng.Grade_Id = grades_eng.Id 
INNER JOIN 
    domain_math_eng ON math_standards_eng.Domain_Math_Eng_Id 
INNER JOIN 
    cluster_eng ON math_standards_eng.Cluster_Eng_Id 

This is what I get when I run the query:

Grade   Domain                       Cluster                                    Standard    
3rd     Counting and cardinality    Know number names and the count sequence    Explain equivalence of fractions in special cases...
3rd     Expressions and Equations   Know number names and the count sequence    Explain equivalence of fractions in special cases...
3rd     Functions                  Know number names and the count sequence     Explain equivalence of fractions in special cases. 
4th     Counting and cardinality    Know number names and the count sequence    Know relative sizes of measurement units within o...
4th     Expressions and Equations   Know number names and the count sequence    Know relative sizes of measurement units within o...

The text value for Standard keeps on showing the same value per grade and I do not know why. 3rd Will keep showing the same thing, and then the next grade will change to a new value and repeat over and over. Lastly, each table has a 1:M relationship with standard as they each appear multiple times in the standard Table. Any advice would be greatly appreciated.

Upvotes: 0

Views: 67

Answers (1)

devlin carnate
devlin carnate

Reputation: 8591

You are missing the = part of your INNER JOIN on domain_math_eng and cluster_eng. I would expect something like:

SELECT grades_eng.Grade, domain_math_eng.Domain, cluster_eng.Cluster, math_standards_eng.Standard FROM math_standards_eng 
INNER JOIN grades_eng ON math_standards_eng.Grade_Id = grades_eng.Id 
INNER JOIN domain_math_eng ON math_standards_eng.Domain_Math_Eng_Id = domain_math_eng.Id
INNER JOIN cluster_eng ON math_standards_eng.Cluster_Eng_Id = cluster_eng.Id

Upvotes: 1

Related Questions