0

I want to modify this sql:

SELECT DISTINCT
    date,
    name,
    age
FROM
    reports1

SELECT DISTINCT
    date,
    name,
    info,
FROM
    reports2

Group by 
    date,
    name

But I want to select from reports1 not only date, name & age but also additional_info which shouldn't be distinct. How do I do this?

CDspace
  • 2,639
  • 18
  • 30
  • 36
user2950593
  • 9,233
  • 15
  • 67
  • 131
  • look into unions – Jay Lane Sep 21 '17 at 19:56
  • 1
    Can you share some sample data and the result you're trying to get for it? – Mureinik Sep 21 '17 at 19:57
  • Possible duplicate of [Selecting distinct values from two tables](https://stackoverflow.com/questions/5158600/selecting-distinct-values-from-two-tables) – Jay Lane Sep 21 '17 at 19:57
  • if you add additional column on your select which are not distinct to date, name, age combination, then it wouldn't be distinct anymore. just add the additional column from the table that you want to select – Ferdinand Gaspar Sep 21 '17 at 23:30

1 Answers1

0

use JOIN to join result of 2 tables like this:

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

For more understanding on join : https://www.w3schools.com/sql/sql_join.asp

Kashif Qureshi
  • 1,460
  • 2
  • 13
  • 20