Month: June 2006

  • On Request

    Imagine you’re a rat in a scientific lab. There are two doors leading into your cage, one red, one blue. Every morning, the red door opens, and a bit of cheese tumbles in. Sometimes you can eat the cheese, and all is well. Other times, there’s a long silver thing stuck in it. You find that if you eat the cheese where it lies on the metal cage floor, it makes your tongue hurt, your paw jump, and gives you a very bad headache. (more…)

  • Unified Rows

    Here are a couple table definitions:

    CREATE TABLE `users1` (
    `name` varchar(10) default NULL,
    `birthday` date default NULL
    );

    CREATE TABLE `users2` (
    `name` varchar(10) default NULL,
    `birthday` date default NULL
    );

    After inserting some data, we get the following row counts:

    SELECT COUNT(*) FROM users1;
    +----------+
    | COUNT(*) |
    +----------+
    | 15 |
    +----------+

    SELECT COUNT(*) FROM users2;
    +----------+
    | COUNT(*) |
    +----------+
    | 12 |
    +----------+

    Now, for this query:

    SELECT * FROM users1 UNION SELECT * FROM users2;

    How many rows will be in the result set? (Choose the best answer)

    a) Exactly 27
    b) At least 12
    c) At least 15
    d) Between 1 and 27
    e) Zero or more

    d) Between 1 and 27. Default behavior for UNION is DISTINCT. If all 27 rows in the two tables are identical, there will be only 1 row in the result. If all are unique, there will be 27 rows.