我有三张桌子叫

**Student Table**
-------------
id    name
-------------
1     ali
2     ahmed
3     john
4     king

**Course Table**
-------------
id    name
-------------
1     physic
2     maths
3     computer
4     chemistry

**Bridge**
-------------
sid    cid
-------------
1     1
1     2
1     3
1     4
2     1
2     2
3     3
3     4
4     1
4     2

现在,让学生的名字和他学习过的课程名称一起显示,

**Result**
---------------------------
Student        Course
---------------------------
ahmed         physic
ahmed         maths
ahmed         computer
ahmed         chemistry
ali           physic
ali           maths
john          computer
john          chemistry
king          physic
king          maths

我构建以下查询

select s.name as Student, c.name as Course from student s, course c join bridge b on c.id = b.cid order by s.name

但它不会返回所需的结果...

如果我想找出谁是管理者而不是其他人,那么规范化的形式应该是什么:

**employee**
-------------------
id        name
-------------------
1         ali
2         king
3         mak
4         sam
5         jon

**manage**
--------------
mid      eid
--------------
1         2
1         3
3         4
4         5

想要得到这个结果:

**result**
--------------------
Manager      Staff
--------------------
ali          king
ali          mak
mak          sam
sam          jon

推荐答案

简单地使用:

select s.name "Student", c.name "Course"
from student s, bridge b, course c
where b.sid = s.sid and b.cid = c.cid 

Mysql相关问答推荐

如何改进对另一个表中多行的查询依赖性

对具有依赖子查询结果的2列使用等式比较来优化连接

MySQL Group by或Distinct in Window函数

mysql 获取每个单词的第一个字母

根据时间戳分组删除

Travis 构建失败并出现错误 LOAD DATA LOCAL INFILE 文件请求因访问限制而被拒绝

基于关系的每个实体有一个真值和多个假值

MySQL DISTINCT 日期仅返回特定表的 1 个值.相同的查询适用于其他表

MySQL如何通过外键ID Select 多行?

从 SQL 中的左连接和内连接中减go 计数

如何判断嵌套查询返回的元组中的每个条目是否相同?

如何在不违反唯一约束的情况下交换 MySQL 中两行的值?

如何在mysql select查询中获取两个日期之间的日期列表

由于在 MySQL 中使用保留字作为表名或列名导致的语法错误

WHERE 子句中的条件顺序会影响 MySQL 性能吗?

使用 Java 通过 SSH 连接到远程 MySQL 数据库

使用 Docker 我收到错误:SQLSTATE[HY000] [2002] 没有这样的文件或目录

如何在 MySQL 中删除此索引?

数据截断:第 1 行的logo列数据太长

MySQL 错误 2014 的原因在其他无缓冲查询处于活动状态时无法执行查询