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 8463217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:24:01+00:00 2026-06-10T14:24:01+00:00

I built working MySQL query: SELECT v.*, u.username FROM video AS v, users AS

  • 0

I built working MySQL query:

  SELECT 
    v.*, u.username 
  FROM 
    video AS v, users AS u
  WHERE
    v.type = 'public' 
  AND 
    v.user_ID = u.user_ID

Now I want to add a third table and count() results from the table comments where video_ID from this table will be equal to those from the table video.

I tried this but it wasn’t successful:

  SELECT 
    v.*, u.username, count(c.video_ID)
  FROM 
    video AS v, users AS u, comments AS c
  WHERE
    v.type = 'public' 
  AND 
    v.user_ID = u.user_ID
  AND
    v.video_ID = c.video_ID

In return I want to get the number of comments related to certain video_ID‘s.

I don’t understand how to make it work correctly in one query.

Could you please help me out?

Thank you in advance,
Ilia

  • 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-10T14:24:03+00:00Added an answer on June 10, 2026 at 2:24 pm

    If you are using an aggregate function like a COUNT in a query, you need to specify the grouping with a GROUP BY clause.

    Try this

    SELECT  
        v.*, 
        u.username, 
        count(c.video_ID) AS comment_count
    FROM  
    video AS v
         INNER JOIN users AS u ON     v.user_ID = u.user_ID 
         INNER JOIN comments AS c ON    v.video_ID = c.video_ID
    WHERE 
     v.type = 'public'  
    GROUP BY
        v.id, 
        u.username,
        v.v.add_time
    ORDER BY
        v.add_time
    

    While MySQL lets you leave out the some elements of the GROUP BY clause, it is good practice to specify them.

    When joining two tables, it is good practice to use the INNER JOIN syntax, rather than a WHERE filter.

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

Sidebar

Related Questions

$result = $db_con->query(SELECT SQL_CALC_FOUND_ROWS * FROM users LIMIT 0,10); $count_result = $db_con->query(SELECT FOUND_ROWS() as
I am working on to build a query in MYSQL by which I can
I am working on a UDP server built with boost::asio and I started from
I'm working on an html5 application built on CouchDB. I want to make sure
First off, here's my SQL query: SELECT research_cost, tech_name, (SELECT research_cost FROM technologies WHERE
Okay. I've built here a mysql query browser, like navicat. Using MySQLdb to perform
I am working on a web application, which historically was built on a PHP/MySQL
I am working on a system using php/mysql where I am allowing users to
I'm working on a PHP/MySQL rating system right now. For the user to be
<?php function f__table ($table,$cols,$order,$desc) { $comma=implode(,,$cols); $query = 'select '.$comma.' from '.$table.' order by

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.