Function Details ($id) {
$query = $this->db->query ("Select T1.gradename, t2.* from grade as t1,student as t2 where StudentID = ' $id ' and T2.G Radeid = T1.gradeid ");
return $query->result ();
}
There are two tables, student tables and grade tables, the call method passed over the ID variable used to query the student information for the specified number, and now ask, I want to query all the field values of Sutdent and gradename values.
Because student and grade are foreign key associations student the Gradeid and grade tables of the table Gradeid, Gradename exists grade table.
I write the statement is wrong, can not execute, please big guy to help, thank you.
Reply to discussion (solution)
What is the error message? SQL does not see the problem ...
Select S.*, g.gradename from student as s left joins grade as G on s.gradeid = G.gradeid where S.studentid = $id
What is the error message? SQL does not see the problem ...
#1052-column ' StudentID ' in WHERE clause is ambiguous
Wander_wind wrote it right, but I don't understand why I was wrong.
Column ' StudentID ' in WHERE clause is ambiguous
The StudentID column in the WHERE clause is ambiguous.
In a multi-table query, it is necessary for the column name to be prefixed with it, otherwise MySQL is not clearly divided.
Select T1.gradename, t2.* from grade as t1,student as t2 where T1.studentid = ' $id ' and T2.gradeid = T1.gradeid
Wander_wind wrote it right, but I don't understand why I was wrong.
The most common reason for this error is that the same field in the associated table is causing the prefix of the table alias as it was said upstairs.