0 rows affected (0.02 sec) mysql> INSERT INTO t2 VALUES ('two'); ERROR 1406 (22001): Data too long for column 'val' at row 1 mysql> SELECT * FROM t2; Empty set (0.00 sec) 9/63
indepyear は1対1で紐づかないので、そんなものを許すと(本来)何が返ってく るかわからない ‐ mysql> SELECT continent, COUNT(*), indepyear FROM country GROUP BY continent; ERROR 1055 (42000): Expression #3 of SELECT list is not in GROUP BY clause and contains n onaggregated column 'world.country.IndepYear' which is not functionally dependent on colu mns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by 12/63
FROM t1 JOIN t2 ON t1.val = t2.val WHERE t1.val LIKE 'a%'; +----+-------------+-------+------------+-------+---------------+------+---------+-----------+--------+----------+--------------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+---------------+------+---------+-----------+--------+----------+--------------------------+ | 1 | SIMPLE | t2 | NULL | index | val | val | 99 | NULL | 996424 | 100.00 | Using where; Using index | | 1 | SIMPLE | t1 | NULL | ref | val | val | 131 | d1.t2.val | 1 | 100.00 | Using where; Using index | +----+-------------+-------+------------+-------+---------------+------+---------+-----------+--------+----------+--------------------------+ 2 rows in set, 2 warnings (0.02 sec) mysql> SHOW WARNINGS; +---------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------+ | Level | Code | Message | +---------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------+ | Warning | 1739 | Cannot use ref access on index 'val' due to type or collation conversion on field 'val' | | Note | 1003 | /* select#1 */ select `d1`.`t1`.`num` AS `num`,`d1`.`t1`.`val` AS `val`,`d1`.`t2`.`num` AS `num`,`d1`.`t2`.`val` AS `val` from `d1`.`t1` join `d1`.`t2` where ((`d1`.`t1`.`val` li ke 'a%') and (`d1`.`t1`.`val` = `d1`.`t2`.`val`)) | +---------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------+ 2 rows in set (0.00 sec) 25/63
t1 JOIN t3 ON t1.val = t3.val WHERE t1.val LIKE 'a%'; ERROR 1267 (HY000): Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_ja_0900_as _cs,IMPLICIT) for operation '=' mysql> EXPLAIN SELECT * FROM t1 JOIN t3 ON t1.val = t3.val COLLATE utf8mb4_unicode_ci WHERE t1.val LIKE 'a%'; +----+-------------+-------+------------+-------+---------------+------+---------+------+--------+- ---------+---------------------------------------------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+---------------+------+---------+------+--------+- ---------+---------------------------------------------------------+ | 1 | SIMPLE | t1 | NULL | range | val | val | 131 | NULL | 125750 | 100.00 | Using where; Using index | | 1 | SIMPLE | t3 | NULL | index | val | val | 131 | NULL | 996424 | 100.00 | Using where; Using index; Using join buffer (hash join) | +----+-------------+-------+------------+-------+---------------+------+---------+------+--------+- ---------+---------------------------------------------------------+ 2 rows in set, 3 warnings (0.02 sec) 26/63
FETCH FIRST n ROWS ONLY ? MySQLの場合は LIMIT n OFFSET m とか LIMIT m, n Oracleは知らないけどMySQLのOFFSETは0オリジン ‐ ユニークキーで ORDER BY していない限り、 LIMIT .. OFFSET .. で返ってくる行 は「不定」 WHEREとかとの兼ね合いで選ばれたインデックスで「見つかった順」にしか返さないので、使う インデックスが変わると戻ってくる行が変わる ‐ ユニークでない限り、 ORDER BY c1 ASC, c2 ASC でc1もc2も同じレコード同士がどういう順番 で返ってくるかはわからない ‐ 42/63