[英]MySQL a query to get user_id and password from two different tables
How can I write a query to get ID and password from the two tables?如何编写查询以从两个表中获取 ID 和密码?
Also, can I make a login table that contains ID and password as a foreign key from the two tables?另外,我可以从两个表中创建一个包含 ID 和密码作为外键的登录表吗?
(Do I have to change the professeur ID and student ID columns to have the same name?) (我是否必须将教授 ID 和学生 ID 列更改为具有相同的名称?)
Look here about "join": https://www.cloudways.com/blog/how-to-join-two-tables-mysql/看这里关于“加入”: https://www.cloudways.com/blog/how-to-join-two-tables-mysql/
Use a union select:使用联合 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
;
Please note that at least the fields professeur_id and student_id must have an alias because of their different name.请注意,至少字段professeur_id 和student_id必须具有别名,因为它们的名称不同。 But giving all fields an alias is a good practice.
但是给所有字段一个别名是一个很好的做法。
For more information (not only on select statement) please go to official MySQL documentation有关更多信息(不仅在 select 声明上),请 go 到官方 MySQL 文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.