1

好吧,我有一些这样的桌子..

table TopicForum
-------------------------
 - idforum (PK)
 - iduser (FK)
 - subject
 - content


table Usermember
--------------------------------
-iduser (PK)
-password
-accesslevel

table student
-------------------------------
-idstudent (PK)
-iduser (FK)
-name

table teacher
---------------------------------
-idtecher (PK)
-iduser(FK)
-name

table admin
-----------------------------------
-idadmin (PK)
-iduser(FK)
-name

所以我想在学生教师管理员的iduser 的 TopicForum 参考中显示名称..

请帮忙谢谢

4

2 回答 2

0

尝试这个:

SELECT DISTINCT A.name, A.iduser 
FROM (SELECT NAME, iduser FROM Student
      UNION 
      SELECT NAME, iduser FROM Teacher
      UNION
      SELECT NAME, iduser FROM Admin) AS A 
INNER JOIN TopicForum tf ON A.iduser = tf.iduser
于 2013-01-08T14:22:01.570 回答
0

尝试 :

SELECT DISTINCT tf.Subject
FROM TopicForum tf
INNER JOIN (
    SELECT iduser FROM Student
    UNION 
    SELECT iduser FROM Teacher
    UNION
    SELECT iduser FROM Admin
) u ON tf.iduser = u.iduser

我不太明白你为什么要区分iduseridteacher例如。除非你想以某种方式格式化它们(但为什么?)我建议将这两列合并到一个唯一的 id 列中,这可以是与表的一对一关系usermember

于 2013-01-08T14:07:58.337 回答