A Little Noise

June 16, 2006

Unified Rows

Filed under: MySQL Gotchas — snoyes @ 4:06 pm

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

Show Answer ▼

1 Comment »

  1. La commande UNION

    l’énigme en français

    Trackback by Kamelot Blog — August 25, 2006 @ 7:50 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress