比较sql中的列与列

时间:2014-03-14 14:20:50

标签: php sql

我有两张桌子,'学生'和老师'。'学生'有两列' roll',' class'。'老师'还有2列' id',' class'。我想获取一些' roll'来自学生的专栏'表格的某些值为' class'列将与' class'的值匹配老师的专栏' table.can你能帮我解决一下吗?

**student**              **teacher** 
roll     class           id       class

1         one            101       one
2         three          102       three
3         five           103       four

2 个答案:

答案 0 :(得分:1)

SELECT Roll FROM Student S. INNER JOIN老师T ON S.Class = T.Class

答案 1 :(得分:0)

SELECT
    student.roll
FROM
    student
    INNER JOIN teacher ON student.class = teacher.class