Skip to content

Instantly share code, notes, and snippets.

@kwstannard
Last active November 5, 2018 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwstannard/0a2125a01f59f603ea4d30978b85764a to your computer and use it in GitHub Desktop.
Save kwstannard/0a2125a01f59f603ea4d30978b85764a to your computer and use it in GitHub Desktop.
mysql> create temporary table tmp (d INT(11));
Query OK, 0 rows affected (0.02 sec)
/* there are 2 rows being inserted with value of 1 */
mysql> insert into tmp (d) values (1), (2), (1), (3);
Query OK, 4 rows affected (0.01 sec)
/* this shows that distinct works */
mysql> select distinct d from tmp;
+------+
| d |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.00 sec)
/* This shows that if a row becomes different then distinct operates off the row */
mysql> select distinct d, RAND() as e from tmp;
+------+---------------------+
| d | e |
+------+---------------------+
| 1 | 0.8762416912952826 |
| 2 | 0.09092339043591487 |
| 1 | 0.8258919090273714 |
| 3 | 0.8566894045627578 |
+------+---------------------+
4 rows in set (0.01 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment