ALL和另一侧的内部联接

ALL和另一侧的内部联接

我想查询要在哪里实现
这与我内在的连接都具有相同的价值
应该是唯一的值作为第一个值
列,在此处的图片中:

mysql - sql-UNION ALL和另一侧的内部联接-LMLPHP

我只想输出的是图片中的红线。

这是我的查询:

  SELECT it.Date AS 'Date', it.invoice AS 'Invoice No.',
         it.company AS 'Company', it.total_amount AS 'Total Amount'
  FROM invoicesummary_tbl it
  WHERE it.total !=0
  UNION ALL
  SELECT itt.Date AS 'Date',rt.revises_no AS 'Invoice_No.', itt.company AS
  'Company',
       itt.total_amount AS 'Total Amount'
  FROM revises_tbl rt
  INNER JOIN invoicesummary_tbl itt
  ON itt.invoice=rt.invoice

最佳答案

使用DISTINCT关键字:

SELECT DISTINCT *
  FROM (SELECT it.Date AS 'Date',
               it.invoice AS 'Invoice No.',
               it.company AS 'Company',
               it.total_amount AS 'TotalAmount'
          FROM invoicesummary_tbl it
         WHERE it.total != 0
        UNION ALL
        SELECT itt.Date AS 'Date',
               rt.revises_no AS 'Invoice_No.',
               itt.company AS 'Company',
               itt.total_amount AS 'Total Amount'
          FROM revises_tbl rt
               INNER JOIN invoicesummary_tbl itt ON itt.invoice = rt.invoice
) AS a

关于mysql - sql-UNION ALL和另一侧的内部联接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46032813/

10-10 22:08