![](/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.