Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8655121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:57:06+00:00 2026-06-12T14:57:06+00:00

I have 3 tables in MySQL USERS uid email password created This is the

  • 0

I have 3 tables in MySQL

USERS
uid
email
password
created

This is the table that have all records of all users

PHOTOS
iid
uid
file
thumb
uploaded

This is the table where all photos posted by each user are kept on

COMMENTS
cid
iid
uid
message
created

This is the table where all the comments on each photo by every user are kept on

What i want is a query that retrives me the amount (COUNT) of comments on every photo for every unique (DISTINCT) user.
For example (the resulting output must be) :

comment_amount  by_user on_picture
3               1       1
2               2       1
2               1       2
5               2       2
6               2       3

so the output could tell us if it is formated something like (example)

3 comments posted by USER1 on PICTURE1
2 comments posted by USER2 on PICTURE1

2 comments posted by USER1 on PICTURE2
5 comments posted by USER2 on PICTURE2

6 comments posted by USER2 on PICTURE3

What i have so far is

SELECT 
users.uid
FROM users
INNER
    JOIN photos
    ON photos.uid = users.uid
INNER
    JOIN comments
    ON comments.iid = photos.iid
    

and here is the sandbox testing

http://sqlfiddle.com/#!2/955d5/1
    

But I don’t know what to do next. Also any language besides MySQL should work as well!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:57:08+00:00Added an answer on June 12, 2026 at 2:57 pm
    SELECT count(*) AS comment_amount, users.uid AS by_user, photos.iid AS on_picture
    FROM users
    INNER
        JOIN photos
        ON photos.uid = users.uid
    INNER
        JOIN comments
        ON comments.iid = photos.iid
    group by users.uid, photos.iid
    

    or just

    SELECT count(*) AS comment_amount, uid AS by_user, iid AS on_picture
    FROM comments
    

    if you just need the data in the comments table

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using php and mysql I have two tables, a users table and a profiles
Lets say I have a MySQL table, Users, like this - ----------------------------------------- ID |
I have a table which looks like this: mysql> SHOW COLUMNS FROM Users; +------------+--------------+------+-----+---------+----------------+
Using MySQL, I have a simple table that logs the IP Address that users
I have a table with such structure: uid sid all integers. This table simulates
I have MySQL database with two tables: users and items. They look like this:
I have two tables users and *activation_details* Users table has these data. uid is
I have two tables in my MySQL database, users and tweets, as follows: TABLE
I have 4 tables. Users, Articles, Langs, LangList Articles table: ..., uid (Users.id), lang
I have a MySQL table called Users. The rows have 4 fields and look

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.