Revision-Zero.org

Talking about computer science

A quick SQL poll

Today's writing is really short and is a poll. So please use the comment feature to answer it. Let consider the tables below for a relational schema about people owning pictures (I suppose that a BLOB column could hold the picture, but this is not important here):

Now, consider the following SQL query that returns the whole people info as well as the number of pictures each of them has in the database:

SELECT id, 
       email,
       name,
       (SELECT count(*) 
          FROM pictures
          WHERE pictures.owner = people.id) as nb_picts
  FROM people

Here is the poll. How do you feel?

  1. Exactly what you'd have written
  2. You prefer to use a GROUP BY
  3. It's probably correct, but you're not sure
  4. You would never write such a query, it's certainly inefficient
  5. The query is incorrect, not allowed in SQL
  6. Other (please explain)

Post your response as a 1-6 number using the comment feature below (there is no particular trap).

Thanks!

Leave a comment

The form below allows you to leave me a comment about the post above. Comments are not automatically rendered below posts, but I would be happy to address interesting questions/issues. Simply leave me a contact address if you prefer a personal answer.