【问题标题】:Get list of items if they match a list into another table如果它们将列表匹配到另一个表中,则获取项目列表
【发布时间】:2022-01-22 17:38:46
【问题描述】:

我有这两个存储数据的表:

create table exchanges
(
    exchange_long_name  text,
    exchange_id         bigint
);

create table active_pairs
(
    exchange_id           integer
);

我想获取exchanges 的列表(如果它们存在/匹配exchange_id 到表active_pairs 中)。这如何使用 JOIN 来实现?

【问题讨论】:

    标签: sql postgresql


    【解决方案1】:
    select  distinct exchanges.exchange_id, exchanges.exchange_long_name
    from exchanges inner join active_pairs
    on exchanges.exchange_id = active_pairs.exchange_id;
    

    【讨论】:

    • 谢谢,我在这里看到一个问题。结果重复。它们应该如何变得独一无二?
    • @user1285928 使用不同的!修正了我的答案
    猜你喜欢
    • 1970-01-01
    • 2021-09-16
    • 2020-05-18
    • 1970-01-01
    • 2019-10-13
    • 1970-01-01
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    相关资源
    最近更新 更多