![](/img/trans.png)
[英]query to get userimage path and user information from two different tables
[英]MySQL a query to get user_id and password from two different tables
如何编写查询以从两个表中获取 ID 和密码?
另外,我可以从两个表中创建一个包含 ID 和密码作为外键的登录表吗?
(我是否必须将教授 ID 和学生 ID 列更改为具有相同的名称?)
使用联合 select:
select
p.professeur_id as id
, p.name as name
, p.password as password
, p.mail as mail
from Professeur p
union select
s.student_id as id
, s.name as name
, s.password as password
, s.mail as mail
from Student s
;
请注意,至少字段professeur_id 和student_id必须具有别名,因为它们的名称不同。 但是给所有字段一个别名是一个很好的做法。
有关更多信息(不仅在 select 声明上),请 go 到官方 MySQL 文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.