ti8er
-
Posts
2 -
Joined
-
Last visited
Posts posted by ti8er
-
-
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 PostsFROM users AS uLEFT JOIN messages AS mUSING (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.
A Question About 'from' In Mysql.
in PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
Posted · Edited by ti8er
I totally understand the answer now...but unfortunately cant edit the post. I think the confusion was because the IF(COUNT...) line in the middle.
"username" is in the "users" table so "SELECT u.username.........FROM users AS u" makes sense.
Hopefully that's the correct understanding.
Thanks