我有這些 Postgres 表:
create table employees
(
id bigint primary key,
account_id number,
first_name varchar(150),
last_name varchar(150)
);
create table accounts
(
id bigint primary key,
account_name varchar(150) not null
);
我需要employees通過 account_id 在表中搜索并列印結果與表中匹配的行accounts。id. 我如何使用 JOIN 來做到這一點?
uj5u.com熱心網友回復:
我很確定這就是你要找的。
SELECT a.id, a.account_name, e.first_name, e.last_name
FROM employees as e
JOIN accounts as a on a.id = e.account_id
WHERE e.account_id = 3
這將允許您在員工表中搜索特定的帳戶 ID 并回傳其相應的帳戶表資訊。
你可以在這里用我的 dbfiddle 檢查這個 - https://www.db-fiddle.com/f/pwzwQTsHuP27UDF17eAQy4/0
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/410443.html
標籤:
