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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:11:20+00:00 2026-06-10T21:11:20+00:00

The following query does what I want. It returns all the resuls in the

  • 0

The following query does what I want. It returns all the resuls in the users table and then if there is a match in the details tble, returns the relevant data

users

id|username

details

id|userid|firstname|lastname


$sql = "SELECT u.*, d.*
FROM `users` u
LEFT JOIN `details` d on
u.id = d.userid
ORDER BY $strorder";

However, when I try to join an additonal table where I want to do the same thing–return all the results of the users table and if there is a match in the third table, return the relevant data (total followers of this user)–it only returns one record.

3rd table

follow

id|followerid|followedid

$sql = "SELECT u.*, d.*, COUNT(f.id)
FROM `users` u
LEFT JOIN `details` d on
u.id = d.userid
LEFT JOIN `follow` f on
u.id = f.followedid
ORDER BY $strorder";

Can anyone see what I am doing wrong? Thanks in advance for any suggestions.

Many thanks.

  • 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-10T21:11:21+00:00Added an answer on June 10, 2026 at 9:11 pm

    Try to avoid * to select fields, it will be clearer to group your datas (even if mysql is quite permissive with groupings).

    When you have an aggregate function (like COUNT, SUM), the other “non aggregated” requested fields should be in a GROUP BY clause.

    Mysql don’t force you to GROUP BY all the fields, but… I think it’s quite a good habit to be “as ANSI as possible” (usefull when you use another DBMS)

    SELECT u.id, u.username, d.firstname, d.lastname, count(*) as numberfollowers
    FROM user u
    LEFT JOIN details d on u.id = d.userid
    LEFT JOIN follow f on u.id = f.followedid
    GROUP BY u.id, u.username, d.firstname, d.lastname --or just GROUP BY u.id with Mysql
    ORDER BY count(*) desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering why the following regex does not match. string query = \1
Why does the following query raise the error below for a row with a
Does anyone know why the following query fails in Derby? delete from MyTable where
Can anyone explain what the following PHP Code does function query($query_string) { if ($query_string
The following query returns the total amount of orders, per week, for the past
I am trying to write a SQL query that returns rows from a table
I'm using the following query which returns the result as below: SELECT subnets.subnet_id ,
I have a MySQL table for competitions called users . Now, I want to
I want to add to my load more posts query below the following line
Following query is used for Getting Categories and one news for each category. How

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.