Jump to content
Larry Ullman's Book Forums

ti8er

Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by ti8er

  1. Hi, 

    Apologies in advance if the answer to this question is very obvious. I've tried googling but haven't found a satisfactory answer.

     

    From page 220 of the Kindle version of your text book. Question 4: "For each user, find the number of messages they’ve posted, converting zeros to the string None"
     
    The answer is:
     
    SELECT u.username,
    IF(COUNT(message_id) > 0, COUNT(message_id), 'None') AS Posts
    FROM users AS u
    LEFT JOIN messages AS m
    USING (user_id)
    GROUP BY (u.user_id);
     
    Shouldn’t line three be “FROM messages AS m”?  (and then instead of "LEFT JOIN messages as m" you "LEFT JOIN users AS u") Since the “message_id” (used for the counting part on the previous line) is “FROM" the messages table and not from the users table? 
     
    It's just a nagging question I had at the back of my mind cause it seems counter intuitive to the English meaning of the word "from". So I tried googling the MYSQL defintion of "FROM" to see if it means something different but couldnt find anything...
     
    Many thanks for your assistance,
     
    p.s. Your book has been very helpful. 
×
×
  • Create New...