Sql从几个表中选择params

时间:2017-09-21 19:55:27

标签: mysql sql

我想修改这个sql:

SELECT DISTINCT
    date,
    name,
    age
FROM
    reports1

SELECT DISTINCT
    date,
    name,
    info,
FROM
    reports2

Group by 
    date,
    name

但我想从reports1中选择datename& ageadditional_info也不应该是不同的。我该怎么做?

1 个答案:

答案 0 :(得分:0)

使用JOIN加入2个表的结果,如下所示:

SELECT DISTINCT
    r1.date,
    r1.name,
    r1.age,
    r2.info
FROM reports1 r1
Join reports2 r2 on r1.date = r2.date and r1.name = r2.name

有关加入的更多信息:https://www.w3schools.com/sql/sql_join.asp