0

I need to get emails in result. First need to get users id from two tables and connect it with users table to get email by id. In result I need only unique emails.

Im trying to construct something like this, but don't think it's right

SELECT distinct 'uid','login.email' 
FROM 'operations' 
left join 'login' on operations.uid=login.id 
UNION
SELECT distinct  'uid','login.email' 
FROM 'operations24' 
left join 'login' on operations.uid=login.id 
Ionic
  • 3,884
  • 1
  • 12
  • 33

1 Answers1

0

You can try this:

SELECT distinct 'ops.uid','login.email' 
FROM (
    SELECT distinct 'uid'
    FROM 'operations' 
    UNION ALL
    SELECT distinct 'uid'
    FROM 'operations24'
) as ops
left join 'login' 
        on ops.uid=login.id 

You can use UNION ALL if the uid's in both tables were totally different If there is any duplicate possible between both selects, better use just UNION this will be slower.

Ionic
  • 3,884
  • 1
  • 12
  • 33
  • Thanks for reply, but I got: Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available. In result: ops.uid login.email ops.uid login.email – Rokas Paškevičius Jul 03 '15 at 12:42
  • Can you try it again, there was an error in the SELECT passage. – Ionic Jul 03 '15 at 13:09
  • Im trying this: SELECT distinct 'ops.uid','login.email' FROM ( SELECT distinct 'uid' FROM operations UNION ALL SELECT distinct 'uid' FROM operations24) as ops left join login on ops.uid=login.id but in result the same - Current selection does not contain a unique column. – Rokas Paškevičius Jul 03 '15 at 13:17
  • This is just a warning. Take a look here: http://stackoverflow.com/questions/18922503/resolution-this-table-does-not-contain-a-unique-column-grid-edit-checkbox-ed – Ionic Jul 03 '15 at 13:26