From a subquery
mysql>
mysql>
mysql>
mysql> CREATE TABLE MATCHES
-> (MATCHNO INTEGER NOT NULL,
-> TEAMNO INTEGER NOT NULL,
-> EmployeeNO INTEGER NOT NULL,
-> WON SMALLINT NOT NULL,
-> LOST SMALLINT NOT NULL,
-> PRIMARY KEY (MATCHNO) );
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> INSERT INTO MATCHES VALUES ( 1, 1, 6, 3, 1);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO MATCHES VALUES ( 2, 1, 6, 2, 3);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO MATCHES VALUES ( 3, 1, 6, 3, 0);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO MATCHES VALUES ( 4, 1, 44, 3, 2);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO MATCHES VALUES ( 5, 1, 83, 0, 3);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO MATCHES VALUES ( 6, 1, 2, 1, 3);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO MATCHES VALUES ( 7, 1, 57, 3, 0);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO MATCHES VALUES ( 8, 1, 8, 0, 3);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO MATCHES VALUES ( 9, 2, 27, 3, 2);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO MATCHES VALUES (10, 2, 104, 3, 2);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO MATCHES VALUES (11, 2, 112, 2, 3);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO MATCHES VALUES (12, 2, 112, 1, 3);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO MATCHES VALUES (13, 2, 8, 0, 3);
Query OK, 1 row affected (0.00 sec)
mysql>
mysql>
mysql>
mysql> CREATE TABLE PENALTIES
-> (PAYMENTNO INTEGER NOT NULL,
-> EmployeeNO INTEGER NOT NULL,
-> PAYMENT_DATE DATE NOT NULL,
-> AMOUNT DECIMAL(7,2) NOT NULL,
-> PRIMARY KEY (PAYMENTNO) );
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> INSERT INTO PENALTIES VALUES (1, 6, '1980-12-08',100);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO PENALTIES VALUES (2, 44, '1981-05-05', 75);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO PENALTIES VALUES (3, 27, '1983-09-10',100);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO PENALTIES VALUES (4,104, '1984-12-08', 50);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO PENALTIES VALUES (5, 44, '1980-12-08', 25);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO PENALTIES VALUES (6, 8, '1980-12-08', 25);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO PENALTIES VALUES (7, 44, '1982-12-30', 30);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO PENALTIES VALUES (8, 27, '1984-11-12', 75);
Query OK, 1 row affected (0.00 sec)
mysql>
mysql>
mysql>
mysql> SELECT (SELECT COUNT(*)
-> FROM PENALTIES),
-> (SELECT COUNT(*)
-> FROM MATCHES);
+------------------------------------------------+----------------------------------------------+
| (SELECT COUNT(*)
FROM PENALTIES) | (SELECT COUNT(*)
FROM MATCHES) |
+------------------------------------------------+----------------------------------------------+
| 8 | 13 |
+------------------------------------------------+----------------------------------------------+
1 row in set (0.00 sec)
mysql>
mysql>
mysql> drop table matches;
Query OK, 0 rows affected (0.00 sec)
mysql> drop table penalties;
Query OK, 0 rows affected (0.00 sec)
Related examples in the same category