0% found this document useful (0 votes)
13 views8 pages

Project Coding

The document contains a MySQL session where the user connects to a MySQL database and retrieves information about databases and tables. It specifically focuses on the 'instagram_clone_db' database, listing the tables within it and querying the 'users' table to find the oldest users based on their creation date. The output includes user IDs, usernames, and their creation timestamps.

Uploaded by

v.manohar792
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

Project Coding

The document contains a MySQL session where the user connects to a MySQL database and retrieves information about databases and tables. It specifically focuses on the 'instagram_clone_db' database, listing the tables within it and querying the 'users' table to find the oldest users based on their creation date. The output includes user IDs, usernames, and their creation timestamps.

Uploaded by

v.manohar792
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

Microsoft Windows [Version 10.0.22621.

2861]
(c) Microsoft Corporation. All rights reserved.

C:\Users\V.MANOHAR>mysql -u root -p
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 8.0.34 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW DATABASES;


+--------------------+
| Database |
+--------------------+
| emp_db |
| information_schema |
| instagram_clone_db |
| librarydb |
| mysql |
| new |
| performance_schema |
| product_details |
| sales |
| sys |
+--------------------+
10 rows in set (0.00 sec)

mysql> USE instagram_clone_db


Database changed
mysql> SHOW TABLES;
+------------------------------+
| Tables_in_instagram_clone_db |
+------------------------------+
| comments |
| follows |
| likes |
| photo_tags |
| photos |
| tags |
| users |
+------------------------------+
7 rows in set (0.00 sec)

mysql> -- CHALLENGES
mysql> -- FIND 5 OLDEST USERS
mysql> SELECT * FROM USERS;
+-----+-----------------------+---------------------+
| id | username | created_at |
+-----+-----------------------+---------------------+
| 1 | Kenton_Kirlin | 2017-02-16 18:22:11 |
| 2 | Andre_Purdy85 | 2017-04-02 17:11:21 |
| 3 | Harley_Lind18 | 2017-02-21 11:12:33 |
| 4 | Arely_Bogan63 | 2016-08-13 01:28:43 |
| 5 | Aniya_Hackett | 2016-12-07 01:04:39 |
| 6 | Travon.Waters | 2017-04-30 13:26:14 |
| 7 | Kasandra_Homenick | 2016-12-12 06:50:08 |
| 8 | Tabitha_Schamberger11 | 2016-08-20 02:19:46 |
| 9 | Gus93 | 2016-06-24 19:36:31 |
| 10 | Presley_McClure | 2016-08-07 16:25:49 |
| 11 | Justina.Gaylord27 | 2017-05-04 16:32:16 |
| 12 | Dereck65 | 2017-01-19 01:34:14 |
| 13 | Alexandro35 | 2017-03-29 17:09:02 |
| 14 | Jaclyn81 | 2017-02-06 23:29:16 |
| 15 | Billy52 | 2016-10-05 14:10:20 |
| 16 | Annalise.McKenzie16 | 2016-08-02 21:32:46 |
| 17 | Norbert_Carroll35 | 2017-02-06 22:05:43 |
| 18 | Odessa2 | 2016-10-21 18:16:56 |
| 19 | Hailee26 | 2017-04-29 18:53:40 |
| 20 | Delpha.Kihn | 2016-08-31 02:42:30 |
| 21 | Rocio33 | 2017-01-23 11:51:15 |
| 22 | Kenneth64 | 2016-12-27 09:48:17 |
| 23 | Eveline95 | 2017-01-23 23:14:19 |
| 24 | Maxwell.Halvorson | 2017-04-18 02:32:44 |
| 25 | Tierra.Trantow | 2016-10-03 12:49:21 |
| 26 | Josianne.Friesen | 2016-06-07 12:47:01 |
| 27 | Darwin29 | 2017-03-18 03:10:07 |
| 28 | Dario77 | 2016-08-18 07:15:03 |
| 29 | Jaime53 | 2016-09-11 18:51:57 |
| 30 | Kaley9 | 2016-09-23 21:24:20 |
| 31 | Aiyana_Hoeger | 2016-09-29 20:28:12 |
| 32 | Irwin.Larson | 2016-08-26 19:36:22 |
| 33 | Yvette.Gottlieb91 | 2016-11-14 12:32:01 |
| 34 | Pearl7 | 2016-07-08 21:42:01 |
| 35 | Lennie_Hartmann40 | 2017-03-30 03:25:22 |
| 36 | Ollie_Ledner37 | 2016-08-04 15:42:20 |
| 37 | Yazmin_Mills95 | 2016-07-27 00:56:44 |
| 38 | Jordyn.Jacobson2 | 2016-05-14 07:56:26 |
| 39 | Kelsi26 | 2016-06-08 17:48:08 |
| 40 | Rafael.Hickle2 | 2016-05-19 09:51:26 |
| 41 | Mckenna17 | 2016-07-17 17:25:45 |
| 42 | Maya.Farrell | 2016-12-11 18:04:45 |
| 43 | Janet.Armstrong | 2016-10-06 07:57:44 |
| 44 | Seth46 | 2016-07-07 11:40:27 |
| 45 | David.Osinski47 | 2017-02-05 21:23:37 |
| 46 | Malinda_Streich | 2016-07-09 21:37:08 |
| 47 | Harrison.Beatty50 | 2016-09-02 03:48:38 |
| 48 | Granville_Kutch | 2016-06-26 03:10:22 |
| 49 | Morgan.Kassulke | 2016-10-30 12:42:31 |
| 50 | Gerard79 | 2016-08-23 19:47:44 |
| 51 | Mariano_Koch3 | 2017-04-17 14:14:46 |
| 52 | Zack_Kemmer93 | 2017-01-01 05:58:22 |
| 53 | Linnea59 | 2017-02-07 07:49:34 |
| 54 | Duane60 | 2016-12-21 04:43:38 |
| 55 | Meggie_Doyle | 2017-04-04 12:17:34 |
| 56 | Peter.Stehr0 | 2016-08-22 18:05:42 |
| 57 | Julien_Schmidt | 2017-02-02 23:12:48 |
| 58 | Aurelie71 | 2016-05-31 06:20:57 |
| 59 | Cesar93 | 2016-10-18 16:42:43 |
| 60 | Sam52 | 2017-03-30 22:03:45 |
| 61 | Jayson65 | 2016-10-14 19:10:53 |
| 62 | Ressie_Stanton46 | 2016-12-20 15:09:09 |
| 63 | Elenor88 | 2016-05-08 01:30:41 |
| 64 | Florence99 | 2016-10-06 23:08:31 |
| 65 | Adelle96 | 2016-10-01 00:37:57 |
| 66 | Mike.Auer39 | 2016-07-01 17:36:15 |
| 67 | Emilio_Bernier52 | 2016-05-06 13:04:30 |
| 68 | Franco_Keebler64 | 2016-11-13 20:09:27 |
| 69 | Karley_Bosco | 2016-06-24 23:38:52 |
| 70 | Erick5 | 2017-04-05 23:44:47 |
| 71 | Nia_Haag | 2016-05-14 15:38:50 |
| 72 | Kathryn80 | 2016-10-11 09:01:57 |
| 73 | Jaylan.Lakin | 2016-06-10 23:58:52 |
| 74 | Hulda.Macejkovic | 2017-01-25 17:17:28 |
| 75 | Leslie67 | 2016-09-21 05:14:01 |
| 76 | Janelle.Nikolaus81 | 2016-07-21 09:26:09 |
| 77 | Donald.Fritsch | 2017-01-07 10:05:41 |
| 78 | Colten.Harris76 | 2016-10-10 02:38:53 |
| 79 | Katarina.Dibbert | 2016-11-03 13:14:11 |
| 80 | Darby_Herzog | 2016-05-06 00:14:21 |
| 81 | Esther.Zulauf61 | 2017-01-14 17:02:34 |
| 82 | Aracely.Johnston98 | 2016-07-25 18:49:10 |
| 83 | Bartholome.Bernhard | 2016-11-06 02:31:23 |
| 84 | Alysa22 | 2017-01-01 17:44:43 |
| 85 | Milford_Gleichner42 | 2017-04-30 07:50:51 |
| 86 | Delfina_VonRueden68 | 2017-03-21 12:02:14 |
| 87 | Rick29 | 2017-02-24 11:25:08 |
| 88 | Clint27 | 2016-06-02 21:40:10 |
| 89 | Jessyca_West | 2016-09-14 23:47:05 |
| 90 | Esmeralda.Mraz57 | 2017-03-03 11:52:27 |
| 91 | Bethany20 | 2016-06-03 23:31:53 |
| 92 | Frederik_Rice | 2016-07-06 21:56:29 |
| 93 | Willie_Leuschke | 2017-02-15 01:40:53 |
| 94 | Damon35 | 2016-10-31 14:44:27 |
| 95 | Nicole71 | 2016-05-09 17:30:22 |
| 96 | Keenan.Schamberger60 | 2016-08-28 14:57:28 |
| 97 | Tomas.Beatty93 | 2017-02-11 11:38:55 |
| 98 | Imani_Nicolas17 | 2017-01-31 22:59:34 |
| 99 | Alek_Watsica | 2016-12-10 07:43:58 |
| 100 | Javonte83 | 2017-03-27 22:06:37 |
+-----+-----------------------+---------------------+
100 rows in set (0.00 sec)

mysql> SELECT ID,USERNAME,CREATED_AT


-> FROM USERS
-> ORDER BY CREATED_AT ASC;
+-----+-----------------------+---------------------+
| ID | USERNAME | CREATED_AT |
+-----+-----------------------+---------------------+
| 80 | Darby_Herzog | 2016-05-06 00:14:21 |
| 67 | Emilio_Bernier52 | 2016-05-06 13:04:30 |
| 63 | Elenor88 | 2016-05-08 01:30:41 |
| 95 | Nicole71 | 2016-05-09 17:30:22 |
| 38 | Jordyn.Jacobson2 | 2016-05-14 07:56:26 |
| 71 | Nia_Haag | 2016-05-14 15:38:50 |
| 40 | Rafael.Hickle2 | 2016-05-19 09:51:26 |
| 58 | Aurelie71 | 2016-05-31 06:20:57 |
| 88 | Clint27 | 2016-06-02 21:40:10 |
| 91 | Bethany20 | 2016-06-03 23:31:53 |
| 26 | Josianne.Friesen | 2016-06-07 12:47:01 |
| 39 | Kelsi26 | 2016-06-08 17:48:08 |
| 73 | Jaylan.Lakin | 2016-06-10 23:58:52 |
| 9 | Gus93 | 2016-06-24 19:36:31 |
| 69 | Karley_Bosco | 2016-06-24 23:38:52 |
| 48 | Granville_Kutch | 2016-06-26 03:10:22 |
| 66 | Mike.Auer39 | 2016-07-01 17:36:15 |
| 92 | Frederik_Rice | 2016-07-06 21:56:29 |
| 44 | Seth46 | 2016-07-07 11:40:27 |
| 34 | Pearl7 | 2016-07-08 21:42:01 |
| 46 | Malinda_Streich | 2016-07-09 21:37:08 |
| 41 | Mckenna17 | 2016-07-17 17:25:45 |
| 76 | Janelle.Nikolaus81 | 2016-07-21 09:26:09 |
| 82 | Aracely.Johnston98 | 2016-07-25 18:49:10 |
| 37 | Yazmin_Mills95 | 2016-07-27 00:56:44 |
| 16 | Annalise.McKenzie16 | 2016-08-02 21:32:46 |
| 36 | Ollie_Ledner37 | 2016-08-04 15:42:20 |
| 10 | Presley_McClure | 2016-08-07 16:25:49 |
| 4 | Arely_Bogan63 | 2016-08-13 01:28:43 |
| 28 | Dario77 | 2016-08-18 07:15:03 |
| 8 | Tabitha_Schamberger11 | 2016-08-20 02:19:46 |
| 56 | Peter.Stehr0 | 2016-08-22 18:05:42 |
| 50 | Gerard79 | 2016-08-23 19:47:44 |
| 32 | Irwin.Larson | 2016-08-26 19:36:22 |
| 96 | Keenan.Schamberger60 | 2016-08-28 14:57:28 |
| 20 | Delpha.Kihn | 2016-08-31 02:42:30 |
| 47 | Harrison.Beatty50 | 2016-09-02 03:48:38 |
| 29 | Jaime53 | 2016-09-11 18:51:57 |
| 89 | Jessyca_West | 2016-09-14 23:47:05 |
| 75 | Leslie67 | 2016-09-21 05:14:01 |
| 30 | Kaley9 | 2016-09-23 21:24:20 |
| 31 | Aiyana_Hoeger | 2016-09-29 20:28:12 |
| 65 | Adelle96 | 2016-10-01 00:37:57 |
| 25 | Tierra.Trantow | 2016-10-03 12:49:21 |
| 15 | Billy52 | 2016-10-05 14:10:20 |
| 43 | Janet.Armstrong | 2016-10-06 07:57:44 |
| 64 | Florence99 | 2016-10-06 23:08:31 |
| 78 | Colten.Harris76 | 2016-10-10 02:38:53 |
| 72 | Kathryn80 | 2016-10-11 09:01:57 |
| 61 | Jayson65 | 2016-10-14 19:10:53 |
| 59 | Cesar93 | 2016-10-18 16:42:43 |
| 18 | Odessa2 | 2016-10-21 18:16:56 |
| 49 | Morgan.Kassulke | 2016-10-30 12:42:31 |
| 94 | Damon35 | 2016-10-31 14:44:27 |
| 79 | Katarina.Dibbert | 2016-11-03 13:14:11 |
| 83 | Bartholome.Bernhard | 2016-11-06 02:31:23 |
| 68 | Franco_Keebler64 | 2016-11-13 20:09:27 |
| 33 | Yvette.Gottlieb91 | 2016-11-14 12:32:01 |
| 5 | Aniya_Hackett | 2016-12-07 01:04:39 |
| 99 | Alek_Watsica | 2016-12-10 07:43:58 |
| 42 | Maya.Farrell | 2016-12-11 18:04:45 |
| 7 | Kasandra_Homenick | 2016-12-12 06:50:08 |
| 62 | Ressie_Stanton46 | 2016-12-20 15:09:09 |
| 54 | Duane60 | 2016-12-21 04:43:38 |
| 22 | Kenneth64 | 2016-12-27 09:48:17 |
| 52 | Zack_Kemmer93 | 2017-01-01 05:58:22 |
| 84 | Alysa22 | 2017-01-01 17:44:43 |
| 77 | Donald.Fritsch | 2017-01-07 10:05:41 |
| 81 | Esther.Zulauf61 | 2017-01-14 17:02:34 |
| 12 | Dereck65 | 2017-01-19 01:34:14 |
| 21 | Rocio33 | 2017-01-23 11:51:15 |
| 23 | Eveline95 | 2017-01-23 23:14:19 |
| 74 | Hulda.Macejkovic | 2017-01-25 17:17:28 |
| 98 | Imani_Nicolas17 | 2017-01-31 22:59:34 |
| 57 | Julien_Schmidt | 2017-02-02 23:12:48 |
| 45 | David.Osinski47 | 2017-02-05 21:23:37 |
| 17 | Norbert_Carroll35 | 2017-02-06 22:05:43 |
| 14 | Jaclyn81 | 2017-02-06 23:29:16 |
| 53 | Linnea59 | 2017-02-07 07:49:34 |
| 97 | Tomas.Beatty93 | 2017-02-11 11:38:55 |
| 93 | Willie_Leuschke | 2017-02-15 01:40:53 |
| 1 | Kenton_Kirlin | 2017-02-16 18:22:11 |
| 3 | Harley_Lind18 | 2017-02-21 11:12:33 |
| 87 | Rick29 | 2017-02-24 11:25:08 |
| 90 | Esmeralda.Mraz57 | 2017-03-03 11:52:27 |
| 27 | Darwin29 | 2017-03-18 03:10:07 |
| 86 | Delfina_VonRueden68 | 2017-03-21 12:02:14 |
| 100 | Javonte83 | 2017-03-27 22:06:37 |
| 13 | Alexandro35 | 2017-03-29 17:09:02 |
| 35 | Lennie_Hartmann40 | 2017-03-30 03:25:22 |
| 60 | Sam52 | 2017-03-30 22:03:45 |
| 2 | Andre_Purdy85 | 2017-04-02 17:11:21 |
| 55 | Meggie_Doyle | 2017-04-04 12:17:34 |
| 70 | Erick5 | 2017-04-05 23:44:47 |
| 51 | Mariano_Koch3 | 2017-04-17 14:14:46 |
| 24 | Maxwell.Halvorson | 2017-04-18 02:32:44 |
| 19 | Hailee26 | 2017-04-29 18:53:40 |
| 85 | Milford_Gleichner42 | 2017-04-30 07:50:51 |
| 6 | Travon.Waters | 2017-04-30 13:26:14 |
| 11 | Justina.Gaylord27 | 2017-05-04 16:32:16 |
+-----+-----------------------+---------------------+
100 rows in set (0.00 sec)

mysql> SELECT * FROM USERS


-> ORDER BY CREATED_AT
-> LIMIT 5;
+----+------------------+---------------------+
| id | username | created_at |
+----+------------------+---------------------+
| 80 | Darby_Herzog | 2016-05-06 00:14:21 |
| 67 | Emilio_Bernier52 | 2016-05-06 13:04:30 |
| 63 | Elenor88 | 2016-05-08 01:30:41 |
| 95 | Nicole71 | 2016-05-09 17:30:22 |
| 38 | Jordyn.Jacobson2 | 2016-05-14 07:56:26 |
+----+------------------+---------------------+
5 rows in set (0.00 sec)

mysql> -- 2. WHAT DAYS OF THE WEEK DO MOST USERS REGISTER ON?


mysql> SELECT
-> DAYNAME(CREATED_AT) AS DAY_OF_THE_WEEK,
-> COUNT(*) AS TOTAL_COUNT
-> FROM USERS
-> GROUP BY DAY_OF_THE_WEEK
-> ORDER BY TOTAL_COUNT DESC;
+-----------------+-------------+
| DAY_OF_THE_WEEK | TOTAL_COUNT |
+-----------------+-------------+
| Thursday | 16 |
| Sunday | 16 |
| Friday | 15 |
| Tuesday | 14 |
| Monday | 14 |
| Wednesday | 13 |
| Saturday | 12 |
+-----------------+-------------+
7 rows in set (0.00 sec)

mysql> -- 3. FIND THE USERS WHO HAVE NEVER POSTED A PHOTO?


mysql> SELECT
-> USER ID,USERNAME,USERS.CREATED_AT AS USER_JOINING_DATE
-> FROM USERS
-> LEFT JOIN PHOTOS
-> ON USER.ID = PHOTOS.USER_ID
-> WHERE PHOTOS.USER_ID IS NULL;
ERROR 1054 (42S22): Unknown column 'USER' in 'field list'
mysql> SELECT
-> USER ID,USERNAME,USERS.CREATED_AT AS USER_JOINING_DATE
-> FROM USERS
-> LEFT JOIN PHOTOS
-> ON USERS.ID = PHOTOS.USER_ID
-> WHERE PHOTOS.USER_ID IS NULL;
ERROR 1054 (42S22): Unknown column 'USER' in 'field list'
mysql> SELECT
-> USERS.ID,USERNAME,USERS.CREATED_AT AS USER_JOINING_DATE
-> FROM USERS
-> LEFT JOIN PHOTOS
-> ON USERS.ID = PHOTOS.USER_ID
-> WHERE PHOTOS.USER_ID IS NULL;
+----+---------------------+---------------------+
| ID | USERNAME | USER_JOINING_DATE |
+----+---------------------+---------------------+
| 5 | Aniya_Hackett | 2016-12-07 01:04:39 |
| 7 | Kasandra_Homenick | 2016-12-12 06:50:08 |
| 14 | Jaclyn81 | 2017-02-06 23:29:16 |
| 21 | Rocio33 | 2017-01-23 11:51:15 |
| 24 | Maxwell.Halvorson | 2017-04-18 02:32:44 |
| 25 | Tierra.Trantow | 2016-10-03 12:49:21 |
| 34 | Pearl7 | 2016-07-08 21:42:01 |
| 36 | Ollie_Ledner37 | 2016-08-04 15:42:20 |
| 41 | Mckenna17 | 2016-07-17 17:25:45 |
| 45 | David.Osinski47 | 2017-02-05 21:23:37 |
| 49 | Morgan.Kassulke | 2016-10-30 12:42:31 |
| 53 | Linnea59 | 2017-02-07 07:49:34 |
| 54 | Duane60 | 2016-12-21 04:43:38 |
| 57 | Julien_Schmidt | 2017-02-02 23:12:48 |
| 66 | Mike.Auer39 | 2016-07-01 17:36:15 |
| 68 | Franco_Keebler64 | 2016-11-13 20:09:27 |
| 71 | Nia_Haag | 2016-05-14 15:38:50 |
| 74 | Hulda.Macejkovic | 2017-01-25 17:17:28 |
| 75 | Leslie67 | 2016-09-21 05:14:01 |
| 76 | Janelle.Nikolaus81 | 2016-07-21 09:26:09 |
| 80 | Darby_Herzog | 2016-05-06 00:14:21 |
| 81 | Esther.Zulauf61 | 2017-01-14 17:02:34 |
| 83 | Bartholome.Bernhard | 2016-11-06 02:31:23 |
| 89 | Jessyca_West | 2016-09-14 23:47:05 |
| 90 | Esmeralda.Mraz57 | 2017-03-03 11:52:27 |
| 91 | Bethany20 | 2016-06-03 23:31:53 |
+----+---------------------+---------------------+
26 rows in set (0.00 sec)
mysql> -- 4. WHO GOT MOST LIKES ON A SINGLE PHOTO
mysql> SELECT
-> USERS.ID AS USER_ID,
-> USERNAME,PHOTOS.ID AS PHOTO_ID,
-> PHOTOS.IMAGE_URL,
-> COUNT(*) AS TOTAL_LIKES_COUNT
-> FROM PHOTOS
-> JOIN LIKES
-> ON PHOTOS.ID = LIKES.PHOTO_ID
-> JOIN USERS
-> ON USERS.ID = PHOTOS.USER_ID
-> GROUP BY PHOTOS.ID
-> ORDER BY TOTAL_LIKES_COUNT DESC
-> LIMIT 1;
+---------+---------------+----------+---------------------+-------------------+
| USER_ID | USERNAME | PHOTO_ID | IMAGE_URL | TOTAL_LIKES_COUNT |
+---------+---------------+----------+---------------------+-------------------+
| 52 | Zack_Kemmer93 | 145 | https://jarret.name | 48 |
+---------+---------------+----------+---------------------+-------------------+
1 row in set (0.01 sec)

mysql> -- 5. How many times does the average user post?


mysql> SELECT
-> ROUND(
-> (SELECT COUNT(*) FROM PHOTOS)/(SELECT COUNT(*) FROM USERS),2) AS
AVG_USER_POST;
+---------------+
| AVG_USER_POST |
+---------------+
| 2.57 |
+---------------+
1 row in set (0.00 sec)

mysql> -- 6. What are the top 5 most commonly used hashtags?


mysql> SELECT
-> TAGS.ID AS TAG_ID,
-> TAGS.TAGE_NAME,
-> COUNT(*) AS TOTAL_TAGS_COUNT
-> EXIT;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'EXIT' at
line 5
mysql> SELECT
-> TAGS.ID AS TAG_ID,
-> TAGS.TAG_NAME,
-> COUNT(*) AS TOTAL_TAGS_COUNT
-> FROM TAGS
-> JOIN PHOTO_TAGS
-> ON TAGS.ID = PHOTO_TAGS.TAG_ID
-> GROUP BY TAGS.ID
-> ORDER BY TOTAL_TAGS_COUNT DESC
-> LIMIT 5;
+--------+----------+------------------+
| TAG_ID | TAG_NAME | TOTAL_TAGS_COUNT |
+--------+----------+------------------+
| 21 | smile | 59 |
| 20 | beach | 42 |
| 17 | party | 39 |
| 13 | fun | 38 |
| 18 | concert | 24 |
+--------+----------+------------------+
5 rows in set (0.00 sec)

mysql> -- 7. Find the number of users who have liked every single photo on the
site?
mysql> SELECT
-> USERS.ID AS USER_ID,
-> USERS.USERNAME,
-> COUNT(*) AS TOTAL_USER_LIKES
-> FROM USERS
-> JOIN LIKES
-> ON USERS.ID = LIKES.USER_ID
-> GROUP BY USERS.ID
-> HAVING TOTAL_USERS_LIKES = (
-> SELECT COUNT(*) FROM PHOTOS
-> );
ERROR 1054 (42S22): Unknown column 'TOTAL_USERS_LIKES' in 'having clause'
mysql> SELECT
-> USERS.ID AS USER_ID,
-> USERS.USERNAME,
-> COUNT(*) AS TOTAL_USER_LIKES
-> FROM USERS
-> JOIN LIKES
-> ON USERS.ID = LIKES.USER_ID
-> GROUP BY USERS.ID
-> HAVING TOTAL_USER_LIKES = (
-> SELECT COUNT(*) FROM PHOTOS
-> );
+---------+--------------------+------------------+
| USER_ID | USERNAME | TOTAL_USER_LIKES |
+---------+--------------------+------------------+
| 5 | Aniya_Hackett | 257 |
| 14 | Jaclyn81 | 257 |
| 21 | Rocio33 | 257 |
| 24 | Maxwell.Halvorson | 257 |
| 36 | Ollie_Ledner37 | 257 |
| 41 | Mckenna17 | 257 |
| 54 | Duane60 | 257 |
| 57 | Julien_Schmidt | 257 |
| 66 | Mike.Auer39 | 257 |
| 71 | Nia_Haag | 257 |
| 75 | Leslie67 | 257 |
| 76 | Janelle.Nikolaus81 | 257 |
| 91 | Bethany20 | 257 |
+---------+--------------------+------------------+
13 rows in set (0.01 sec)

mysql>

You might also like