Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-7240

Cannot use "group by" with "left join"

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 10.0.13
    • Fix Version/s: 10.0.16
    • Component/s: Optimizer
    • Labels:
      None
    • Environment:
      CentOS release 6.5 (Final)

      Description

      I get the wrong result when I join 2 tables and use group by at the same time.
      How I can fix this problem?

      MariaDB [workspace]> DROP TABLE IF EXISTS t1;
      Query OK, 0 rows affected (0.00 sec)
       
      MariaDB [workspace]> DROP TABLE IF EXISTS t2;
      Query OK, 0 rows affected (0.00 sec)
       
      MariaDB [workspace]> CREATE TABLE t1(id CHAR(16), PRIMARY KEY(id));
      Query OK, 0 rows affected (0.02 sec)
       
      MariaDB [workspace]> INSERT INTO t1 VALUES ('78622');
      Query OK, 1 row affected (0.00 sec)
       
      MariaDB [workspace]> INSERT INTO t1 VALUES ('786220');
      Query OK, 1 row affected (0.00 sec)
       
      MariaDB [workspace]> CREATE TABLE t2(id CHAR(16), VAR INT DEFAULT NULL, PRIMARY KEY(id));
      Query OK, 0 rows affected (0.04 sec)
       
      MariaDB [workspace]> INSERT INTO t2 VALUES ('78622',1);
      Query OK, 1 row affected (0.00 sec)

      MariaDB [workspace]> SELECT id, VAR FROM t1 LEFT JOIN t2 USING(id) GROUP BY id;
      +--------+------+
      | id     | VAR  |
      +--------+------+
      | 78622  | NULL |
      | 786220 | NULL |
      +--------+------+
      2 rows in set (0.00 sec)
       
      MariaDB [workspace]> SELECT id, VAR FROM t1 LEFT JOIN t2 USING(id);
      +--------+------+
      | id     | VAR  |
      +--------+------+
      | 78622  |    1 |
      | 786220 | NULL |
      +--------+------+
      2 rows in set (0.00 sec)

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              psergei Sergei Petrunia
              Reporter:
              takuya Takuya Aoki
              Votes:
              2 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Git Integration