SQL association query uses alias to report error

I have two associated tables:

student{
    id,
    class_id,
    name,
    age,
    comment
}
class{
    id,
    name,
    grade,
    comment
}

 Now execute the following sql:

select s.id as id, s.name as name, s.age.as age, c.grade as grade  from student s join class c on s.class_id = c.id;

  report an error

java.sql.SQLException: Column 'age' not found.

  It is found that the age field is only in the student table, and an error will be reported when an alias is used (a field unique to a table cannot use an alias)

  Therefore, the above sql is modified to the following sql, which can be executed correctly:

select s.id as id, s.name as name, age, c.grade  from student s join class c on s.class_id = c.id;

  The reason for the source code level will be studied later and then added!

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325094919&siteId=291194637